[BZOJ2530] [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

题目分析

每次找一对没有连边的点对将其删掉
由于这对点之间没有连边,因此两个点不可能都存在于团中,也就是说我至少删掉了1个不在团中的点
那么不超过次操作后所有不在团中的点都会被删掉 此时最多删掉了个点
剩余的点构成了一个团,大小,任选其中个点输出即可
时间复杂度

#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
int n,m;
bool f[3010][3010],v[3010];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        f[x][y]=f[y][x]=1;
    }
    for(int i=1;i<=n;i++)
        if(!v[i])
            for(int j=i+1;j<=n;j++)
                if(!v[j]&&!f[i][j])
                {
                    v[i]=1,v[j]=1;
                    break;
                }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(!v[i]) printf("%d ",i),cnt++;
        if(cnt==n/3) break;
    }
    return 0;
}

发表评论

邮箱地址不会被公开。 必填项已用*标注