日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

题目1444:More is better

發布時間:2023/11/27 生活经验 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 题目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 <iostream>
  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<n;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<<temp<<endl;
114 
115  
116 
117    }
118 
119         return 0;
120 
121 }

?

?

轉載于:https://www.cnblogs.com/xiaoyesoso/p/4265124.html

總結

以上是生活随笔為你收集整理的题目1444:More is better的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。