"Turn" POJ 2492 A Bug ' s life: base and check advanced

Source: Internet
Author: User

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

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.