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 ;}