bzoj 2530 [Poi2011]Party 构造

本文针对POI2011 Party问题提供了一种解决方案,通过去除不存在直接连边的点来缩小搜索范围,最终找出一个大小为N/3的团。题目要求在给定的图中寻找一个特定规模的团,即节点子集,使得该子集中的所有节点两两之间都有直接连边。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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的复杂度即可。
 
 1 #include<cstring>
 2 #include<cmath>
 3 #include<cstdio>
 4 #include<algorithm>
 5 #include<iostream>
 6 
 7 #define N 3007
 8 
 9 #define Wb putchar(' ')
10 #define We putchar('\n')
11 #define rg register int
12 using namespace std;
13 inline int read()
14 {
15     int x=0,f=1;char ch=getchar();
16     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
17     while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
18     return x*f;
19 }
20 inline void write(int x)
21 {
22     if(x<0) putchar('-'),x=-x;
23     if (x==0) putchar(48);
24     int num=0;char c[15];
25     while(x) c[++num]=(x%10)+48,x/=10;
26     while(num) putchar(c[num--]);
27 }
28 
29 int n,m,cnt;
30 int a[N][N],vis[N];
31 
32 int main()
33 {
34     n=read(),m=read();
35     for (rg i=1;i<=m;i++)
36     {
37         int x=read(),y=read();
38         a[x][y]=a[y][x]=true;
39     }
40     for (int i=1;i<=n;i++)
41         for (int j=i+1;j<=n&&!vis[i];j++)
42             if (!vis[j]&&!a[i][j])
43                 vis[i]=vis[j]=true;
44     for (int i=1;i<=n&&cnt<n/3;i++)
45         if (!vis[i]) write(i),Wb;
46 }

 

转载于:https://www.cnblogs.com/fengzhiyuan/p/8983600.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值