2530: [Poi2011]Party

Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special Judge
Submit: 364  Solved: 213
[Submit][Status][Discuss]

Description

给定一张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
 
如果两个点没连边,则不可能属于团,所以直接去除,n^2的复杂度即可。
 
 #include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<iostream> #define N 3007 #define Wb putchar(' ')
#define We putchar('\n')
#define rg register int
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
while(isdigit(ch)){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
}
inline void write(int x)
{
if(x<) putchar('-'),x=-x;
if (x==) putchar();
int num=;char c[];
while(x) c[++num]=(x%)+,x/=;
while(num) putchar(c[num--]);
} int n,m,cnt;
int a[N][N],vis[N]; int main()
{
n=read(),m=read();
for (rg i=;i<=m;i++)
{
int x=read(),y=read();
a[x][y]=a[y][x]=true;
}
for (int i=;i<=n;i++)
for (int j=i+;j<=n&&!vis[i];j++)
if (!vis[j]&&!a[i][j])
vis[i]=vis[j]=true;
for (int i=;i<=n&&cnt<n/;i++)
if (!vis[i]) write(i),Wb;
}

bzoj 2530 [Poi2011]Party 构造的更多相关文章

  1. BZOJ 2530 Poi2011 Party 【枚举】

    BZOJ 2530 Poi2011 Party Description Byteasar intends to throw up a party. Naturally, he would like i ...

  2. BZOJ 2217: [Poi2011]Lollipop 构造 + 思维

    Description 有一个长度为n的序列a1,a2,...,an.其中ai要么是1("W"),要么是2("T").现在有m个询问,每个询问是询问有没有一个连 ...

  3. [bzoj 2216] [Poi2011] Lightning Conductor

    [bzoj 2216] [Poi2011] Lightning Conductor Description 已知一个长度为n的序列a1,a2,-,an. 对于每个1<=i<=n,找到最小的 ...

  4. bzoj 2528: [Poi2011]Periodicity【kmp+构造】

    神仙构造,做不来做不来 详见:http://vfleaking.blog.163.com/blog/static/174807634201329104716122/ #include<iostr ...

  5. [BZOJ 2212] [Poi2011] Tree Rotations 【线段树合并】

    题目链接:BZOJ - 2212 题目分析 子树 x 内的逆序对个数为 :x 左子树内的逆序对个数 + x 右子树内的逆序对个数 + 跨越 x 左子树与右子树的逆序对. 左右子树内部的逆序对与是否交换 ...

  6. [BZOJ 2350] [Poi2011] Party 【Special】

    题目链接: BZOJ - 2350 题目分析 因为存在一个 2/3 n 大小的团,所以不在这个团中的点最多 1/3 n 个. 牺牲一些团内的点,每次让一个团内的点与一个不在团内的点抵消删除,最多牺牲 ...

  7. BZOJ 2212: [Poi2011]Tree Rotations( 线段树 )

    线段树的合并..对于一个点x, 我们只需考虑是否需要交换左右儿子, 递归处理左右儿子. #include<bits/stdc++.h> using namespace std; #defi ...

  8. bzoj 2217 [Poi2011]Lollipop 乱搞 贪心

    2217: [Poi2011]Lollipop Time Limit: 15 Sec  Memory Limit: 64 MBSec  Special JudgeSubmit: 383  Solved ...

  9. Luogu3516 POI2011 Shift 构造

    传送门 题意:给出一个长为$N$的排列,有两种操作:$A$:将最后一个数字放到第一个:$B$:将第三个数字放到第一个.一次性使用某种操作$k$次写作$kA$或$kB$,其中在$kA$中$k < ...

随机推荐

  1. Kafka安装之三 spring-kafka实践

    一.spring-kafka配置详解 1.1 要是用spring-kafka 我们首先要在pom要.xml中引入spring-kafka包 <dependencies> <depen ...

  2. Python中的构造函数

    Python中的构造函数是__init__函数.在Python中,子类如果定义了构造函数,而没有调用父类的,那么Python不会自动调用,也就是说父类的构造函数不会执行. 比如有test.py的mod ...

  3. USACO 2.3.3 Zero Sum 和为零(深搜枚举)

    Description 请考虑一个由1到N(N=3, 4, 5 ... 9)的数字组成的递增数列:1 2 3 ... N. 现在请在数列中插入“+”表示加,或者“-”表示减,抑或是“ ”表示空白,来将 ...

  4. c# webBrowser打开pdf问题

    1.生成模式使用release加*86尝试,使用debug则webBrowser不生效

  5. C++:构造函数1——普通构造函数

    前言:构造函数是C+中很重要的一个概念,这里对其知识进行一个简单的总结 一.构造函数的定义 1.类中的构造函数名与类名必须相同 2.构造函数没有函数的返回类值型说明符 [特别注意]: a.构造函数的返 ...

  6. Spring 依赖的Jar包简介

    Spring 依赖的Jar包简介 Spring的依赖关系 依赖关系分组 JAR文件 说 明 ant ant.jar, ant-junit.jar, ant-launcher.jar Spring采用A ...

  7. web.config详解(转载)

    该文为转载 原文地址:http://www.cnblogs.com/gaoweipeng/archive/2009/05/17/1458762.html 花了点时间整理了一下ASP.NET Web.c ...

  8. 继承&构造函数

    子父类中的构造函数的特点. 在子类构造对象时,发现,访问子类构造函数时,父类也运行了. 为什么呢? 原因是:在子类的构造函数中第一行有一个默认的隐式语句. super(); 子类的实例化过程:子类中所 ...

  9. WPF浏览器应用程序与JS的互调用(不用WebBrowser)

    首先说些题外话,很久没有写博客了,空间里面的大部分文章还是11年写的.那时候刚毕业就来到这家公司,参与到一个Asp.net MVC的项目开发中,这个项目是一个全新的项目,连项目开发框架都没有,亏得领导 ...

  10. spring mvc4 找不到静态文件js/css/html 404

    说明: http://localhost:8080 指向的目录是WEB-INF所在的目录,也就是说请求静态资源时都是从该根目录开始查找.建议将所有静态文件放到和WEB-INF同级的目录下. 以 htt ...