A Bug ' s lifeTime
limit:15000/5000 MS (java/others) Memory limit:32768/32768 K (java/others) total submission (s): 13709 Acc epted Submission (s): 4449Problem Description
BackgroundProfessor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature, different genders and that they only interact with bugs of the opposite gender. In he experiment, individual bugs and their interactions were easy to identify, because numbers were printed on their BAC Ks.
problem Given A list of bugs interactions, decide whether the experiment supports his assumption of both genders with no homosexual Bugs or if it contains some bug interactions that falsify it. inputthe first line of the input contains the number O F Scenarios. Each scenario starts with one line giving the number of bugs (at least one, and up to) and the number of interactions (up to 1000000) separated by a single space. In the following lines, each interaction was given in the form of both distinct bug numbers separated by a single space. Bugs was numbered consecutively starting from One. outputthe output for every scenario was a line containing "scenario #i: ", where I am the number of the scenario starting at 1, followed by one line saying either" No suspicious bugs found! " If the experiment is consistent with he assumption about the bugs ' sexual behavior, or ' suspicious bugs found! ' if Profe Ssor Hopper ' s assumption is definitely wrong. sample Input23; Sample Outputscenario #1: Suspicious bugs found! Scenario #2: No Suspicious Bugs found! topic: To give you a number of bugs, to ensure they are the opposite sex, look at the end there is no homosexuality ' thinking analysis: Basic and check set, maintenance and root node relationship can poj1703 the same type of code:
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intmaxn= -+ -;intFA[MAXN];intRELATE[MAXN];//record gender relationship with parent node, 1 for heterosexual, 0 for same sexintn,m;intKase=0;intRootintx) { if(X==fa[x])returnx; intt=root (fa[x]); RELATE[X]= (Relate[x]+relate[fa[x]])%2; FA[X]=T; returnfa[x];}voidMergeintXinty) { intfx=root (x); intfy=root (y); if(FX==FY)return; FA[FX]=fy; RELATE[FX]= (relate[y]+relate[x]+1)%2; return;}intMain () {intT; intb; scanf ("%d",&T); while(t--) {scanf ("%d%d",&n,&m); for(intI=1; i<=n;i++) Fa[i]=i,relate[i]=0; BOOLflag=false; for(intj=1; j<=m;j++) {scanf ("%d%d",&a,&b); if(Root (a) ==root (b) &&relate[a]==Relate[b]) {Flag=true; } Elsemerge (A, b); //printf ("yes\n"); } //printf ("dsasd\n");printf"Scenario #%d:\n",++Kase); if(flag) printf ("Suspicious bugs found!\n\n"); Elseprintf"No Suspicious bugs found!\n\n"); } return 0;}
Hdu 1829 basis and check set, check gay