bzoj 2530: [Poi2011]Party
2017-10-13 16:01
363 查看
Description
Byteasar intends to throw up a party. Naturally, he would like it to be a success. Furthermore, Byteasar is quite certain that to make it so it suffices if all invited guests know each other. He is currently trying to come up with a list of his friends he would like to invite. Byteasar has friends, where is divisible by 3. Fortunately, most of Byteasar’s friends know one another. Furthermore, Byteasar recalls that he once attended a party where there were2/3 n of his friends, and where everyone knew everyone else. Unfortunately, Byteasar does not quite remember anything else from that party… In particular, he has no idea which of his friends attended it. Byteasar does not feel obliged to throw a huge party, but he would like to invite at least n/3of his friends. He has no idea how to choose them, so he asks you for help.给定一张N(保证 N 是 3 的倍数)个节点 M 条边的图,并且保证该图存在一个大小至少为2n3的团。
请输出该图的任意一个大小为n3的团。 一个团的定义为节点的一个子集,该子集中的点两两有直接连边。
输入: 第一行是两个整数N,M。 接下来有 M 行,每行两个整数 A,B,表示 A 和 B 有连边。保证无重边。
输出: n3个整数,表示你找到的团。 数据范围:
3≤N≤3000,2≤M≤[n(n−1)/2]
Input
In the first line of the standard input two integers, n and M(3<=N<=3000,[3/2 n(2/3 n -1)]/2<=M<=[n(n-1)/2]), are given, separated by a single space. These denote the number of Byteasar’s friends and the number of pairs of his friends who know each other, respectively. Byteasar’s friends are numbered from 1 to . Each of the following lines holds two integers separated by a single space. The numbers in line no.i+1(for i=1,2,…,m) are Ai and Bi(1<=AiOutput
In the first and only line of the standard output your program should print N/3numbers, separated by single spaces, in increasing order. These number should specify the numbers of Byteasar’s friends whom he should invite to the party. As there are multiple solutions, pick one arbitrarily.Sample Input
6 10 2 5 1 4 1 5 2 4 1 3 4 5 4 6 3 5 3 4 3 6
Sample Output
2 4
HINT
Explanation of the example: Byteasar’s friends numbered 1, 3, 4, 5 know one another. However, any pair of Byteasar’s friends who know each other, like 2 and 4 for instance, constitutes a correct solution, i.e., such a pair needs not be part of aforementioned quadruple.Source
鸣谢 Object022&suhangsolution
先普及一下什么是团选择一个图中的若干点,若任意两个点之间均有一条边联通,则这些点组成的集合是一个团。
知道了这个这道题就很简单了
在一个团里的点肯定是两个点之间均有一条边联通
所以不在团里的点肯定没有一条边让他们联通
所以枚举每个点和哪个点之间没有边,然后打一个标记
最后输出还有被标记的点就好了..
code
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; template<typename T> void input(T &x) { x=0; T a=1; register char c=getchar(); for(;c<'0'||c>'9';c=getchar()) if(c=='-') a=-1; for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0'; x*=a; return; } #define MAXN 3010 bool G[MAXN][MAXN],vis[MAXN]; int main() { int n,m; input(n),input(m); for(int i=1;i<=m;i++) { int u,v; input(u),input(v); G[u][v]=G[v][u]=true; } for(int i=1;i<=n;i++) if(!vis[i]) { for(int j=i+1;j<=n;j++) if(!vis[j]&&!G[i][j]&&!G[j][i]) { vis[i]=vis[j]=true; break; } } int cnt=0; for(int i=1;i<=n;i++) if(!vis[i]) { printf("%d ",i); cnt++; if(cnt*3==n) return 0; } return 0; }
相关文章推荐
- BZOJ2530 [Poi2011]Party
- [构造] BZOJ 2530 [Poi2011]Party
- BZOJ 2530 Poi2011 Party 构造
- 【BZOJ2530】[Poi2011]Party (xia)构造
- BZOJ 2530: [Poi2011]Party
- bzoj2530 [Poi2011]Party
- BZOJ2530 : [Poi2011]Party
- bzoj 2530: [Poi2011]Party
- BZOJ2530: [Poi2011]Party
- BZOJ2530 [Poi2011]Party 【贪心】
- 【BZOJ】【P2530】【Poi2011】【Party】【题解】【水题】
- [BZOJ 2350] [Poi2011] Party 【Special】
- 2530: [Poi2011]Party
- BZOJ_2527_[Poi2011]Meteors_整体二分
- [BZOJ 2212] [Poi2011] Tree Rotations 【线段树合并】
- BZOJ2216 [Poi2011]Lightning Conductor 【决策单调性dp】
- 【bzoj2213】[Poi2011]Difference dp
- BZOJ 2527: [Poi2011]Meteors
- [BZOJ2212][Poi2011]Tree Rotations(线段树合并)
- BZOJ 2277 Poi2011 Strongbox 数论