Check the set and train of thought: classify the bug I interact (I think there will be a misunderstanding of "sexual intercourse") as one type to see if there are similar interact behaviors (sexual behavior ), if Suspicious bugs found is output!
[Html]
# Include <iostream>
Using namespace std;
Class Node
{
Public:
Node ()
{
NodeID = 0;
Parent = NULL;
Rank = 0;
}
Node (int id)
{
NodeID = id;
Parent = NULL;
Rank = 0;
}
Int nodeID;
Node * parent;
Int rank;
};
Void MakeSet (Node * node)
{
Node-> parent = node;
Node-> rank = 0;
}
Void LinkSets (Node * node1, Node * node2)
{
If (node1-> rank> node2-> rank)
{
Node2-> parent = node1;
}
Else if (node1-> rank <node2-> rank)
{
Node1-> parent = node2;
}
Else
{
Node1-> parent = node2;
Node2-> rank ++;
}
Return;
}
Node * FindSets (Node * node)
{
If (node-> parent! = Node)
{
Node-> parent = FindSets (node-> parent );
}
Return node-> parent;
}
Void UnionSets (Node * node1, Node * node2)
{
LinkSets (FindSets (node1), FindSets (node2 ));
}
Int main ()
{
Node * pNode [2002];
Node * pLinkNode [2002];
Int iScenario, iCount;
Cin> iScenario;
ICount = 1;
While (iCount <= iScenario)
{
Int iNumber, iInteraction;
Scanf ("% d", & iNumber, & iInteraction );
For (int I = 0; I <iNumber; I ++)
{
PNode [I] = new Node (I + 1 );
MakeSet (pNode [I]);
PLinkNode [I] = NULL;
}
Bool flag = true;
Int iBug1, iBug2;
For (int I = 0; I <iInteraction; I ++)
{
Scanf ("% d", & iBug1, & iBug2 );
If (FindSets (pNode [iBug1-1])! = FindSets (pNode [iBug2-1])
{
If (Fig [iBug1-1] = NULL)
{
PLinkNode [iBug1-1] = pNode [iBug2-1];
}
Else
{
UnionSets (pNode [iBug2-1], pLinkNode [iBug1-1]);
}
If (Fig [iBug2-1] = NULL)
{
PLinkNode [iBug2-1] = pNode [iBug1-1];
}
Else
{
UnionSets (pLinkNode [iBug2-1], pNode [iBug1-1]);
}
}
Else
{
Flag = false;
}
}
Printf ("Scenario # % d: \ n", iCount );
If (flag = false)
{
Printf ("Suspicious bugs found! \ N ");
}
Else
{
Printf ("No suspicious bugs found! \ N ");
}
ICount ++;
}
}
Author: qiul12345