poj2492 A Bug ' s life (and look up the expansion)

Source: Internet
Author: User

C-A Bug ' s life crawling in process ... crawling failedTime limit:10000MS Memory Limit:65536KB 64bit IO Format: %I64D &%i64u SubmitStatus Practice POJ 2492Appoint Description:Csust_11 (2013-04-14)System Crawler (2016-05-13)

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.

It's a good thing to say and look up.

As far as I know, 1. Determine whether to ring 2. Number of rings 3. Counting the number of collections is actually a matter of what you think.

And, of course, the collection and the combined compression path by rank

How do you explain the merger by rank? In fact, it's all about building a relationship with the rank level of two.

int X=find (a);  int Y=find (b);  if (Rank[x]>rank[y])//by rank combined    fa[y]=x;  else  {    fa[x]=y;    if (Rank[x]==rank[y])      rank[y]++;  }
Compressed path (when you see the array is very large, be cautious, such as hdu1272)

The compression path means that the value of the current node is updated during the lookup process until the root node facilitates the next lookup to save time

int find (int x) {if (fa[x]!=x) Fa[x]=find (fa[x]); return fa[x];}

Do not compress the path:

int find (int x)  13.{  While    (fa[x]!=x)   .    X=FA[X];  .    return fa[x];  




This problem really didn't understand at first. Direct and check the result is wrong to hear the teammates say it seems to be divided between men and women also think of a method is to judge

Is there a person in the relationship who has not seen one appear and the other one is good to judge then think of a group of test arrays 1 2 3 4 1 3 ... I think wrong.

Last look at someone else's code understood

Idea: We can divide the male and female into two sets if there is a new relationship inside and check out the ring then it means that the two men are male or female



poj2492 A Bug ' s life (and look up the expansion)

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.