1. 程式人生 > >BZOJ 2530 Poi2011 Party 【列舉】

BZOJ 2530 Poi2011 Party 【列舉】

BZOJ 2530 Poi2011 Party

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條邊的圖,並且保證該圖存在一個大小至少為2N/3的團。
請輸出該圖的任意一個大小為N/3的團。 一個團的定義為節點的一個子集,該子集中的點兩兩有直接連邊。 輸入: 第一行是兩個整數N,M。 接下來有M行,每行兩個整數A,B,表示A和B有連邊。保證無重邊。 輸出: N/3個整數,表示你找到的團。 資料範圍:
3<=N<=3000,[3/2 n(2/3 n -1)]/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<=Ai<Bi<=N), separated by a single space, which denote that the persons Ai and Bi now each other. Every pair of numbers appears at most once on the input.

Output

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.

首先如果任意兩個點之間沒有連邊我們把這兩個點刪除
因為不在團裡面的點最多有n3\frac{n}{3},每次刪除兩個點,團內的點也最多刪除n3\frac{n}{3},最少也會剩下n3\frac{n}{3}個團內的點
所以最後直接在沒有被刪除的點裡面取n3\frac{n}{3}個就好了

#include<bits/stdc++.h>
using namespace std;
#define fu(a,b,c) for(int a=b;a<=c;++a)
#define N 3010
int n,m;
bool vis[N],g[N][N];
int main(){
  scanf("%d%d",&n,&m); 
  fu(i,1,m){
    int x,y;
    scanf("%d%d",&x,&y);
    g[x][y]=1;
  }
  fu(i,1,n)if(!vis[i])
    fu(j,i+1,n)if(!vis[j])
      if(!g[i][j]){vis[i]=vis[j]=1;break;}
  int siz=0;
  fu(i,1,n)if(!vis[i]&&siz<n/3)printf("%d ",i),siz++;
}