Exercise the skills for not giving data of the set type, use and query, and merge by rank.
# Include <iostream>
Using namespace STD;
Typedef struct
{
Long father;
Long Opper;
} Info;
Const long maxn = 2100;
Info hash [maxn];
Inline void make_set ()
{
Long I;
For (I = 0; I <maxn; ++ I)
{
Hash [I]. Father = hash [I]. Opper = I;
}
}
Inline long find (long X)
{
Long r = X;
While (R! = Hash [R]. Father)
{
R = hash [R]. Father;
}
While (R! = Hash [X]. Father)
{
Long J = hash [X]. Father;
Hash [X]. Father = R;
X = J;
}
Return R;
}
Inline void unition (long X, long y)
{
Long FX = find (X );
Long FY = find (y );
Hash [FY]. Father = FX;
}
Int main ()
{
Long T;
Scanf ("% lD", & T );
Long B = 1;
While (t --)
{
Long n, m;
Scanf ("% LD % lD", & N, & M );
Long I;
Make_set ();
Bool doit = true;
For (I = 0; I <m; ++ I)
{
Long from,;
Scanf ("% LD % lD", & from, & );
If (! Doit)
{
Continue;
}
Long F, T;
F = find (from );
T = find ();
If (F = T)
{
Doit = false;
}
If (hash [from]. Opper! = From)
{
Unition (T, hash [from]. Opper );
}
Else
{
Hash [from]. Opper = T;
}
If (hash [to]. Opper! =)
{
Unition (F, hash [to]. Opper );
}
Else
{
Hash [to]. Opper = F;
}
}
Printf ("Scenario # % ld: \ n", B );
+ + B;
If (doit)
{
Puts ("no suspicious bugs found! ");
}
Else
{
Puts ("suspicious bugs found! ");
}
Puts ("");
}
Return 0;
}