Thought reference here (more detailed)
At first it was always a night. Init initialization is written on scanf ... Hey ╮(╯▽╰)╭ anyway! A step closer to understanding and checking the set!
#include <cstdio> #include <cstring>using namespace std; #define SIZE 2000struct node{int Pre; The relationship between int relation;//and parent node 0 same Sex 1 heterosexual}bug[size+1]; int N, M; BOOL Found;void Init () {for (int i=1; i<=n; i++) {bug[i]. Relation = 0;//itself is the same as its own gender bug[i]. Pre = i; } found = false;} int getpre (int n) {if (Bug[n]. Pre = = n) return n; int t = Getpre (Bug[n]. Pre); Bug[n]. Relation = Bug[n]. Relation^bug[bug[n]. Pre]. Relation; Bug[n]. Pre = t; Return Bug[n]. Pre;} void Union (int a, int b) {int Pa = Getpre (a); int Pb = Getpre (b); if (Pa = = Pb) {if (Bug[a]. Relation = = Bug[b]. Relation) found = true; Return } Bug[pa]. Pre = Pb; BUG[PA]. Relation = ~ (Bug[a]. RELATION^BUG[B]. Relation);} int main () {int Snr; scanf ("%d", &snr); int i=1; for (I=1; i<=snr; i++) {scanf ("%d%d", &n, &m); Init (); while (m--) {int A, B; scanf ("%d%d", &a, &b); if (!found) Union (A, b); } printf ("Scenario #%d:\n", i); if (found) printf ("Suspicious bugs found!\n\n"); else printf ("No suspicious Bugs found!\n"); } return 0;}
"Turn" POJ 2492 A Bug ' s life: base and check advanced