1213 how many tables simple and query set Problems

Source: Internet
Author: User

My code:

# Include <cstdio>
# Include <cstring>
# Include <iostream>
Using namespace STD;
Int find (INT num, int A []) {
While (num! = A [num]) // {
Num = A [num];
Return num;
}//

Bool follow (int A, int B, int A []) {
Int I = find (A, );
Int J = find (B, );
// Cout <"zxd ";
// Cout <I <"" <j <"";
If (I = J) return false;
// Cout <"zxd ";
A [I] = J;
Return true;
}


Int main ()
{
Int T;
Scanf ("% d", & T );
While (t --){
// The following two variables are the number of people and the relationship.
Int M, N;
Scanf ("% d", & M, & N );
// Create a dynamic array to save the returned value.
Int * A = new int [M + 1];
For (INT I = 1; I <= m; I ++) A [I] = I; // For (INT I = 1; I <= m; I ++) cout <A [I];

Int A, B, Count = 0;
For (INT I = 0; I <n; I ++ ){
Scanf ("% d", & A, & B );
// Cout <"circulating ing" <A <B <Endl;
If (follow (A, B, A) Count ++;
// Cout <"count ++;" <count <Endl;
}

Printf ("% d \ n", M-count );
Delete [];
}
Return 0;
}

// Here there are two key functions, that is, in the PPT

Int find (int A) // find the root node {While (! = Fa [a]) // I am not the manager a = Fa [a]; return ;}

Int find (int A) // find the root node {While (! = Fa [a]) // I am not the manager a = Fa [a]; return ;}

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.