BestCoder Round #48 ($)HDU5285 wyh2000 and pupil

本文介绍了一个关于二分图划分的问题,旨在通过合理的分组方式提高团队凝聚力。具体任务是将n个学生分成两个小组,使得同一组内的学生相互认识,并且第一组的学生人数尽可能多。文章提供了一种解决方案,包括特殊情况下(如m=0)的处理方法。

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


wyh2000 and pupil

                                                    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
                                                                                Total Submission(s): 1239    Accepted Submission(s): 384


Problem Description
Young theoretical computer scientist wyh2000 is teaching his pupils.

Wyh2000 has n pupils.Id of them are from  1 to  n.In order to increase the cohesion between pupils,wyh2000 decide to divide them into 2 groups.Each group has at least 1 pupil.

Now that some pupils don't know each other(if  a doesn't know  b,then  b doesn't know  a).Wyh2000 hopes that if two pupils are in the same group,then they know each other,and the pupils of the first group must be as much as possible.

Please help wyh2000 determine the pupils of first group and second group. If there is no solution, print "Poor wyh".
 

Input
In the first line, there is an integer  T indicates the number of test cases.

For each case, the first line contains two integers  n,m  indicate the number of pupil and the number of pupils don't konw each other.

In the next m lines,each line contains 2 intergers  x,y(x < y) ,indicates that  x don't know  y and  y don't know  x,the pair  (x,y)  will only appear once.

T10,0n,m100000
 

Output
For each case, output the answer.
 

Sample Input
  
2 8 5 3 4 5 6 1 2 5 8 3 5 5 4 2 3 4 5 3 4 2 4
 

Sample Output
  
5 3 Poor wyh
 

Source



出题人:


如果aa不认识bb,那么在a,ba,b间连一条边,这样有解当且仅当这张图是二分图。

由于可能有多个二分图,而题目要求第一组的人尽可能多,所以贪心的选择即可。

要注意m=0m=0的情况。



#include 
  
   
#include 
   
    
#include 
    
     
#include 
     
      
#include 
      
       
#include 
       
         #include 
         using namespace std; const int MAXN = 1e5 + 10; const int INF = 0x3f3f3f3f; vector
         
           G[MAXN]; int col[MAXN]; int cnt[3]; int n, m; bool DFS(int u) { for (int i=0; i
          
         
       
      
     
    
   
  




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值