首页 > 题目1444:More is better

题目1444:More is better

 

时间限制:3 秒

内存限制:100 兆

特殊判题:

提交:1362

解决:640

题目描述:

Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain requirements.Mr Wang selected a room big enough to hold the boys. The boy who are not been chosen has to leave the room immediately. There are 10000000 boys in the room numbered from 1 to 10000000 at the very beginning. After Mr Wang's selection any two of them who are still in this room should be friends (direct or indirect), or there is only one boy left. Given all the direct friend-pairs, you should decide the best way.

输入:

The first line of the input contains an integer n (0 ≤ n ≤ 100 000) - the number of direct friend-pairs. The following n lines each contains a pair of numbers A and B separated by a single space that suggests A and B are direct friends. (A ≠ B, 1 ≤ A, B ≤ 10000000)

输出: 

The output in one line contains exactly one integer equals to the maximum number of boys Mr Wang may keep.





总感觉这个Mr Wang是个恋童癖有木有==||





 

  1 #include 
  2 
  3 using namespace std;
  4 
  5  
  6 
  7  
  8 
  9  
 10 
 11 struct LNode
 12 
 13 {
 14 
 15    LNode * lchild,*rchild;
 16 
 17    int data;
 18 
 19 };
 20 
 21  
 22 
 23  
 24 
 25 int Tree[10000001];
 26 
 27 int sum[10000001];
 28 
 29  
 30 
 31 int getroot(int x)
 32 
 33 {
 34 
 35     if(Tree[x]==-1) return x;
 36 
 37 else return getroot(Tree[x]);
 38 
 39 }
 40 
 41  
 42 
 43  
 44 
 45  
 46 
 47 int main()
 48 
 49 {
 50 
 51        int n;
 52 
 53    while(cin>>n)
 54 
 55    {
 56 
 57      int i;
 58 
 59  for(i=0;i<10000001;i++)
 60 
 61  {
 62 
 63     Tree[i]=-1;
 64 
 65 sum[i]=1;
 66 
 67  }
 68 
 69  
 70 
 71  
 72 
 73  
 74 
 75  for(i=0;i)
 76 
 77  {
 78 
 79     int a,b;
 80 
 81 cin>>a>>b;
 82 
 83 a=getroot(a);
 84 
 85 b=getroot(b);
 86 
 87 if(a!=b)
 88 
 89 {
 90 
 91    Tree[a]=b;
 92 
 93    sum[b]+=sum[a];
 94 
 95 }
 96 
 97  }
 98 
 99  
100 
101  int temp=1;
102 
103  for(i=0;i<10000001;i++)
104 
105  {
106 
107    if(sum[i]>temp) temp=sum[i];
108 
109  }
110 
111  
112 
113  cout<endl;
114 
115  
116 
117    }
118 
119         return 0;
120 
121 }

 

 

转载于:https://www.cnblogs.com/xiaoyesoso/p/4265124.html

更多相关:

  • 上篇笔记中梳理了一把 resolver 和 balancer,这里顺着前面的流程走一遍入口的 ClientConn 对象。ClientConn// ClientConn represents a virtual connection to a conceptual endpoint, to // perform RPCs. // //...

  • 我的实验是基于PSPNet模型实现二维图像的语义分割,下面的代码直接从得到的h5文件开始往下做。。。 也不知道是自己的检索能力出现了问题还是咋回事,搜遍全网都没有可以直接拿来用的语义分割代码,东拼西凑,算是搞成功了。 实验平台:Windows、VS2015、Tensorflow1.8 api、Python3.6 具体的流程为:...

  • Path Tracing 懒得翻译了,相信搞图形学的人都能看得懂,2333 Path Tracing is a rendering algorithm similar to ray tracing in which rays are cast from a virtual camera and traced through a s...

  • configure_file( [COPYONLY] [ESCAPE_QUOTES] [@ONLY][NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ]) 我遇到的是 configure_file(config/config.in ${CMAKE_SOURCE_DIR}/...

  •     直接复制以下代码创建一个名为settings.xml的文件,放到C:UsersAdministrator.m2下即可