# More are better--hdu1856 (and look for a set)

Source: Internet
Author: User

More is better

Time limit:5000/1000 MS (java/others) Memory limit:327680/102400 K (java/others)
Total submission (s): 18707 Accepted Submission (s): 6873

Problem DESCRIPTIONMR Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it 'll be. Of course there is certain requirements.

Mr Wang selected A, the big enough to the boys. The boy who is not been chosen have to leave the the the-immediately. There is 10000000 boys in the same as the numbered from 1 to 10000000 at the very beginning. After Mr Wang's selection any of the them who was still in the this guest should be friends (direct or indirect), or there is O Nly one boy left. Given all the direct friend-pairs, your should decide the best.

Inputthe first line of the input contains an integer n (0≤n≤100)-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 is direct Friends. (A≠b, 1≤a, b≤10000000)

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

Sample INPUT4 1 2 3 4 5 6 1 6 4 1 2 3 4 5 6 7 8

Sample Output42 HintA and B are friends (direct or indirect), B and C is friends (direct or indirect), then A and C is also friends (indirect). The first sample {1,2,5,6} is the result.  In the second sample {1,2},{3,4},{5,6},{7,8} is four kinds of answers. The meaning of this question is that the input is a friend of two people, two friends of the pot friends have a transitive sex!  Last output how many people are the most friends of each other? Use and check the set, specifically to see the comments section!
`1#include <iostream>2#include <stdio.h>3#include <string.h>4#include <algorithm>5 #defineMAXN 1000006 using namespacestd;7 intran[maxn],per[maxn],via[maxn],num[maxn],n,sum;8 voidInit ()9 {Ten     inti; One      for(i=1; i<=maxn;i++) A     { -per[i]=i; -Num[i] =1;//Record the child nodes that each root node contains the     } - } - intFindintx)//Lookup function - { +     intt=x; -      while(t!=Per[t]) +t=Per[t]; A      intI=x,j; at       while(i!=t) -      { -j=Per[i]; -per[i]=T; -I=j;//Compression Path -      } in      returnT; - } to voidJoinintXinty)//merge function, Merge diagram + { -     intfx=find (x); the     intfy=find (y); *     if(fx!=fy) \$     {Panax NotoginsengPER[FX] =fy; -Num[fy] + =NUM[FX]; thesum =max (sum, num[fy]);//Find out the maximum number of nodes in each tree +     } A     Else the         return ; + } - intMain () \$ { \$     intA,b,i,w,n; -      while(SCANF ("%d", &n)! =EOF) -     { the         if(n = =0){ -printf"1\n");//Special Pit Daddy dataWuyi             Continue; the         } - init (); Wuw=N; -sum =0; About          while(w--) \$         { -scanf"%d%d",&a,&b); -via[a]=1; -via[b]=1; A Join (A, b); +         } theprintf"%d\n", sum); -     } \$     return 0; the}`

More are better--hdu1856 (and look for a set)

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.