"Go" poj-1703-find them, Catch them: The elements within the collection have a relationship, the relationship between the sets is indeterminate

Source: Internet
Author: User

And last night did a Bug ' s life is the same idea of the problem ... There are some small problems when you start doing it, just make progress on a variety of issues.

#include <cstdio> #define Size 100000int N, M;int rel[size+1], pre[size+1];void Init () {for (int i=1; i<=n;        i++) {rel[i]=0;//oneself and own the same gang pre[i]=i;        }}int getpre (int a) {if (pre[a] = = a) return A;        int t = getpre (Pre[a]);        Rel[a] = Rel[a]^rel[pre[a]];        Pre[a] = t; return pre[a];}        void Union (int a, int b) {int Pa = Getpre (a);        int Pb = Getpre (b);        if (Pa = = Pb) return;        PRE[PA] = Pb; REL[PA] = ~ (Rel[a]^rel[b]);}        int main () {int T;        scanf ("%d", &t);                while (t--) {scanf ("%d%d", &n, &m);                Init ();                        while (m--) {char C;                        int A, B;                        GetChar ();//How can this be forgotten ...                        scanf ("%c%d%d", &c, &a, &b);            if (c== ' A ') {                    int Pa = Getpre (a);                                int Pb = Getpre (b); if (PA==PB) if (rel[a] = = Rel[b]) printf ("in t                                    He same gang.\n ");                                else printf ("in different gangs.\n");                        else printf ("Not sure yet.\n");                } else Union (A, b); }} return 0;}

  

"Go" poj-1703-find them, Catch them: The elements within the collection have a relationship, the relationship between the sets is indeterminate

Related Article

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.