A Bug ' s life
| Time Limit: 10000MS |
|
Memory Limit: 65536K |
| Total Submissions: 29011 |
|
Accepted: 9451 |
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.
Source
TUD Programming Contest 2005, Darmstadt, GermanyThe main idea : To find a homosexual ... Start to explain test instructions to Lei elder brother, I think this question may be to determine the binary map, and then the subtle staining, Lei elder brother said is and check set, I think and check set also line, but until the end of the game we have not realized the two methods ... -_-!
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> #include < Algorithm> #include <queue>using namespace std;typedef long long LL; #define MAXN 4010#define MAXM 1000010int pre[ Maxn];int ufind (int k) {int a = k, b; while (pre[k]! =-1) k = pre[k]; while (A! = k) {b = pre[a]; Pre[a] = k; A = b; } return k;} BOOL Same (int a, int b) {return Ufind (a) = = Ufind (b); void Unite (int a, int b) {a = Ufind (a); b = Ufind (b); if (A! = b) Pre[a] = b;} int main () {//Freopen ("Stdin.txt", "R", stdin); int T, CAs, I, J, N, M, A, B, OK; scanf ("%d", &t); for (cas = 1; CAs <= T; ++cas) {printf ("Scenario #%d:\n", CAs); scanf ("%d%d", &n, &m); memset (Pre,-1, sizeof (int) * (2 * N + 1)); OK = 0; while (m--) {scanf ("%d%d", &a, &b); if (OK) continue; if (Same (a, b)) ok = 1; else { Unite (A, B + N); Unite (A + N, b); }} printf (ok?) "Suspicious bugs found!": "No suspicious Bugs found!"); printf ("\ n"); } return 0;}
POJ2492 A Bug ' s life ' and check set '