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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

杭电1856More is better

發(fā)布時(shí)間:2025/3/16 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 杭电1856More is better 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

求大神指點(diǎn)杭電1586more is better,答案對(duì),就是超時(shí)(⊙o⊙)求指點(diǎn)

?

More is better

Time Limit: 5000/1000 MS (Java/Others)????Memory Limit: 327680/102400 K (Java/Others)
Total Submission(s): 19936????Accepted Submission(s): 7313


Problem Description 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.

Input 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)
Output The output in one line contains exactly one integer equals to the maximum number of boys Mr Wang may keep.

Sample Input 4 1 2 3 4 5 6 1 6 4 1 2 3 4 5 6 7 8
Sample Output 4 2HintA and B are friends(direct or indirect), B and C are friends(direct or indirect), then A and C are also friends(indirect).In the first sample {1,2,5,6} is the result. In the second sample {1,2},{3,4},{5,6},{7,8} are four kinds of answers.

#include <iostream> using namespace std; int arr[10000001] ; int num[10000001] ; int Max; inline int find(int r) {while(r!=arr[r])r=arr[r];return r; } inline void judge(int a,int b) {int x,y;x=find(a);y=find(b);if(x!=y){arr[y]=x;num[x]=num[y]+num[x];num[y]=num[x];if(num[y]>Max)Max=num[y];}? ?? } inline void Init() {for(int i=1;i<= 10000001 ;i++){arr[i]=i;num[i]=1;} } int main() {int N,a,b;while (cin>>N){Init();Max=num[1];while(N--){cin>>a>>b;judge(a, b);}cout<<Max<<endl;}return 0; }

?

總結(jié)

以上是生活随笔為你收集整理的杭电1856More is better的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。