Species and collection, TOJ (1706)

Source: Internet
Author: User

Title Link: http://acm.tju.edu.cn/toj/showp1706.html

Very similar to the problem of a gang in Poj, remember to find the suspicious relationship, do not refresh the collection on it.

1706. A Bug ' s life Time limit: 5.0 Seconds Memory Limit: 65536K
Total Runs: 1190 Accepted Runs: multiple test files



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.

Input

The 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.

Output

The output for every scenario are a line containing "scenario #i:", where I am the number of the scenario starting at 1, fo Llowed by one line saying either "No suspicious bugs found!" if the experiment are consistent with he assumption about the Bugs ' sexual behavior, or "suspicious bugs found!" if Professor Hopper ' s assumption is definitely wrong.

Sample Input

23 31 22 31 34 21 23 4

Sample Output

Scenario #1: Suspicious bugs found! Scenario #2: No Suspicious bugs found!

Hint

Huge input,scanf is recommended.



Source: TUD Programming Contest 2005

#include <stdio.h>intfather[ .];intkind[ .];intFind_set (intx) {    if(x!=Father[x]) {        intTMP =Father[x]; FATHER[X]=Find_set (father[x]); KIND[X]= (Kind[x]+kind[tmp])%2; }    returnfather[x];}intMain () {intT; intcases=1; scanf ("%d",&t);  while(t--)    {        intn,m; scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++) {Father[i]=i; Kind[i]=0; }        BOOLFlag =true;  while(m--)        {            intx, y; scanf ("%d%d",&x,&y); intFx,fy; FX=Find_set (x); FY=Find_set (y); if(fx!=FY) {Father[fy]=FX; KIND[FY]= (kind[x]-kind[y]+1)%2; }            Else            {                if(kind[x]==Kind[y]) flag=false; }        }        if(flag) printf ("Scenario #%d:\nno Suspicious bugs found!\n\n", cases++); Elseprintf"Scenario #%d:\nsuspicious Bugs found!\n\n", cases++); }    return 0;}

Species and collection, TOJ (1706)

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.