HDU 1856 more is better

Source: Internet
Author: User

Check simple questions

1 # include <iostream> 2 # include <stdio. h> 3 # include <stdlib. h> 4 # define n 10000005 5 using namespace STD; 6 int par [N]; 7 int M [N]; 8 int find (int x) 9 {10 if (par [x] = x) 11 return X; 12 else13 par [x] = find (par [x]); 14 return par [x]; 15} 16 void Union (int x, int y) 17 {18 int A = find (x); 19 int B = find (y); 20 if (! = B) 21 {22 if (M [a]> = m [B]) // This is to compare 23 {24 par [B] =; 25 m [a] + = m [B]; 26} 27 else28 {29 par [a] = B; 30 m [B] + = m [a]; 31} 32} 33 else34 return; 35} 36 int main () 37 {38 freopen ("input.txt", "r", stdin); 39 int I, x, y, n; 40 while (scanf ("% d", & N )! = EOF) 41 {42 for (I = 0; I <= N; I ++) // The earliest initialization 43 {44 par [I] = I; 45 m [I] = 1; 46} 47 for (I = 1; I <= N; I ++) 48 {49 scanf ("% d ", & X, & Y); 50 Union (x, y); 51} 52 int max =-1; 53 for (I = 0; I <= N; I ++) 54 if (M [I]> MAX) 55 max = m [I]; // find the Max number with the highest number of relatives and output 56 printf ("% d \ n ", max); 57 58} 59 return 0; 60}

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.