POJ 1611 the Suspects (and find out the number of sets)

Source: Internet
Author: User

DescriptionSevere Acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, were recognized as a global threat in Mid-March 2003. To minimize transmission to others, the best strategy are to separate the suspects from others.
In the Not-spreading-your-sickness University (NSYSU), there is many student groups. The Students in the same group Intercommunicate with each other frequently, and a student may join several groups. To prevent the possible transmissions of SARS, the NSYSU collects the member lists of all student groups, and makes the FO Llowing rule in their standard operation procedure (SOP).
Once a member in a group was a suspect, all members of the group are suspects.
However, they find that it's not easy to identify all the suspects when a student is recognized as a suspect. Your job is to write a program which finds all the suspects.InputThe input file contains several cases. Each test case begins with integers n and m in a line, where n is the number of students, and M are the number of group S. Assume that 0 < n <= 30000 and 0 <= m <= 500. Every student is numbered by a unique integer between 0 and n−1, and initially student 0 are recognized as a suspect in all The cases. This was followed by M member lists of the groups and one line per group. Each line begins with a integer k by itself representing the number of members in the group. Following the number of members, there is k integers representing the students in this group. All the integers in a line is separated by at least one space.
A case with n = 0 and M = 0 indicates the end of the input, and need not being processed.OutputFor each case, output the number of suspects in one line.Sample Input
100 42 1 25 10 13 11 12 142 0 12 99 2200 21 55 1 2 3 4 51 00 0
Sample Output
411
Effect:
There are n personal numbers for 0~N,M teams, each team starts with k individuals, then the number of K individuals, numbered 0 is the suspect, and suspects in a team are also suspects, seeking the number of suspects.
Problem Solving Ideas:
Enter n students first, initialize to fa[], then enter the first man FIR of the M team, and after each input a person is compared to fir, and put in a set, and finally judge how many 0~n individuals are in the 0 collection.
and check the link
1#include <cstdio>2 intn,m,ans,i,j,k,fir,fa[30000+ One],a;3 intFindinta)4 {5     if(A = =Fa[a])6     {7         returnA;8     }9     ElseTen     { One         returnfa[a]=find (Fa[a]); A     } - } - voidF1 (intXinty) the { -     intNx,ny; -nx=find (x); -ny=find (y); +     if(NY = =0) -     { +fa[nx]=NY; A     } at     Else -     { -fa[ny]=NX; -     } - } - intMain () in { -      while(SCANF ("%d%d", &n,&m) && (m+N)) to     { +          for(i =0; I < n; i++) -         { thefa[i]=i; *         } $          for(i =0; I < m; i++)Panax Notoginseng         { -scanf"%d%d",&k,&fir); the              for(j =1; J < K; J + +) +             { Ascanf"%d",&a); the F1 (fir,a); +             } -         } $ans=0; $          for(i =0; I < n; i++) -         { -             if(Find (i) = =0) the             { -ans++;Wuyi             } the         } -printf"%d\n", ans); Wu     } -}

POJ 1611 the Suspects (and find out the number of sets)

Contact Us

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.