Codevs 1995 Dark Magician's Gate

Source: Internet
Author: User

Well ...
through the sample, the answer is either unchanged, or *2+1
then
found that if the new edge Same (l[i].f,l[i].t), *2+1
Proof later, the room will be closed ...

 #include <iostream> #include <cstdio> #include <algorithm> #include <
Cstring> using namespace std;
const int MAXN = 200000 + 5;
const int P = 1000000009;
int n,m,p;
int FA[MAXN];
int RANK[MAXN];
    void Init () {for (int i = 0;i <= n;i + +) fa[i] = i;
    memset (rank,0,sizeof (rank));
Return
    } int find (int x) {return fa[x] = = x X:fa[x] = find (fa[x]), void merge (int x,int y) {x = find (x);
    y = find (y);
    if (x = = y) return;
    if (Rank[x] > Rank[y]) swap (x, y);
    Fa[x] = y;
    if (rank[x] = = Rank[y]) rank[y] + +;
Return
} bool Same (int x,int y) {return find (x) = = Find (y);} int f,t;
int k;
    int main () {scanf ("%d%d", &n,&m);
    Init ();
        while (M-) {scanf ("%d%d", &f,&t);
        if (Same (f,t)) K = (k << 1) + 1,k%= P;
        printf ("%d\n", K);
    Merge (f,t);
} return 0; }

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.