HDU 1829/poj 2492 A Bug ' s life

Source: Internet
Author: User

A Bug ' s life

Time limit:15000/5000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 11981 Accepted Submission (s): 3901


Problem Description Background
Professor 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 of 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 is numbered consecutively starting from one.

Outputthe output for every scenario are 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 was consistent with his assumption Abo UT the bugs ' sexual behavior, or ' suspicious bugs found! ' if Professor Hopper ' s assumption is definitely wrong.

Sample Input23 31 22 31 34 21 23 4

Sample Outputscenario #1: Suspicious bugs found! Scenario #2: No Suspicious bugs found! HintHuge input,scanf is recommended. And check the set of topics. Record the distance from the current node to the root node. When the "and" operation is found again, the distance from the two nodes to the root node of the same root node is judged, while the number is odd or even, so long there is contradiction.
/************************************************author:p k28created time:2015/8/15 9:54:22File NAME:4.CP p*************************************************/#include<iostream>#include<cstring>#include<cstdlib>#include<stdio.h>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<iomanip>#include<list>#include<deque>#include<stack>#defineull unsigned long Long#definell Long Long#defineMoD 90001#defineINF 0x3f3f3f3f#defineMAXN 3000+10#defineCLE (a) memset (A,0,sizeof (a))Constull inf = 1LL << A;Const Doubleeps=1e-5;using namespacestd;BOOLcmpintAintb) {    returnA>b;}intFA[MAXN];intD[MAXN];intN,m,mark;voidinit () { for(intI=1; i<=n+5; i++) {D[i]=0; Fa[i]=i; } Mark=0;}intFINDFA (intx) {    if(X==fa[x])returnx; Else{        introot=Findfa (fa[x]); D[X]+=D[FA[X]];//record the distance to the root nodefa[x]=Root; returnFa[x]; }}voidUnion (intAintb) {    intx=Findfa (a); inty=Findfa (b); if(x==y) {        if((d[a]&1) = = (d[b]&1)) mark=1; return ; }    Else{fa[x]=y; D[X]= (d[a]+d[b]+1); }}intMain () {#ifndef Online_judge freopen ("In.txt","R", stdin); #endif    //freopen ("OUT.txt", "w", stdout);    intT; CIN>>T; intb; intCnt=1;  while(t--) {scanf ("%d%d",&n,&m);        Init ();  for(intI=0; i<m;i++) {scanf ("%d%d",&a,&b); if(Mark)Continue;        Union (A, b); } printf ("Scenario #%d:\n", cnt++); if(Mark) printf ("Suspicious bugs found!\n"); Elseprintf"No Suspicious bugs found!\n"); printf ("\ n"); }    return 0;}

HDU 1829/poj 2492 A Bug ' s life

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.