POJ 1611 The Suspects (especially speechless query set)

Source: Internet
Author: User

POJ 1611 The Suspects (especially speechless query set)

A very simple question, I started to use the separation set forest of the query set. I don't know how it is particularly unstable. It's strange that WA has been doing it for countless times, instead, change it to a one-dimensional array .. Sad

AC

#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include #include 
     
      #define PI acos(-1,0)using namespace std;const int maxn = 30010;const int maxm = 100001;#define lson left, m, id<<1#define rson m+1, right, id<<1|1#define min(a,b) (a>b)?b:a#define max(a,b) (a>b)?a:busing namespace std;int father[50000];int num[50000],n,m;int Find(int r){    int i = r,j;    while(father[r]!=r)    {         r=father[r];    }    while(father[i]!=r)    {        j = father[i];        father[i] = r;        i = j;    }    return r;}void init(){for(int i = 0;i < n;i++){father[i] = i;num[i] = 1;}}void Merge(int l,int b){    int y = Find(b);        if(l != y)        {            father[y] = l;        num[l] +=  num[y];        }}int main(){int j,k,l;while(~scanf("%d%d",&n,&m)){if(n==0 && m==0)break;init();int b;while(m--){scanf("%d%d",&k,&l);int x = Find(l);for(j = 1;j < k;j++){scanf("%d",&b);Merge(x,b);}}    printf("%d\n",num[Find(0)]);}return 0;}
     
    
   
  
 


WA

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Define PI acos (-30010) using namespace std; const int maxn = 100001; const int maxm =; # define lson left, m, id <1 # define rson m + 1, right, id <1 | 1 # define min (a, B) (a> B )? B: a # define max (a, B) (a> B )? A: busing namespace std; struct node {int zhi, parent;} T [maxn]; int Find (int x) {return (x = T [x]. parent )? X: Find (T [x]. parent);} void Merge (int x, int y) {int fx, fy; fx = Find (x); fy = Find (y); if (fx! = Fy) {T [fy]. parent = fx; T [fx]. zhi + = T [fy]. zhi ;}} int main () {int m, n, k; while (~ Scanf ("% d", & n, & m) {if (n = 0 & m = 0) break; for (int j = 0; j
      
       
5 3
1 2
2 0 1
3 1 4 5

Answer 3

Sometimes it is a correct result, sometimes it is not, especially speechless.



3

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.