POJ 2492 A Bug ' s life ' and explore '

Source: Internet
Author: User

A Bug ' s life
Time Limit: 10000MS Memory Limit: 65536K
Total Submissions: 29030 Accepted: 9455

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.

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.

Test instructions: Find two bugs that aren't gay.

Reference: http://www.cnblogs.com/dongsheng/archive/2012/08/08/2627917.html

Code:

#include <cstdio> #include <cstring>const int M = 2050;int Fat[m], ral[m];int f (int x) {if (fat[x]! = x) {        int root = fat[x];        Fat[x] = f (fat[x]);    RAL[X] = (ral[x]+ral[root])%2; } return fat[x];}    int main () {int T, V = 1, n, m;    scanf ("%d", &t);        while (T--) {scanf ("%d%d", &n, &m);        int I, a, b;        for (i = 1; i < M; i++) fat[i] = i;        memset (RAL, 0, sizeof (RAL));        int flag = 0;            while (M-) {scanf ("%d%d", &a, &b);            if (flag) continue;                else{int x = f (a); int y = f (b);                if (x = = y) {if (ral[a] = = Ral[b]) flag = 1;                    } else{fat[x] = y;                RAL[X] = (ral[a]+ral[b]+1)%2;       }}} printf ("Scenario #%d:\n", v++);        if (flag) printf ("Suspicious bugs found!\n"); else printf ("No suspiciousBugs found!\n ");    if (t) printf ("\ n"); } return 0;}


POJ 2492 A Bug ' s life ' and explore '

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.