Cod sursa(job #2118570)

Utilizator AlexVulpoiuAlexandru Vulpoiu AlexVulpoiu Data 30 ianuarie 2018 19:12:51
Problema Paduri de multimi disjuncte Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include <cstdio>
using namespace std;
int n,m,x,y,op,t[100001];
int main()
{
    freopen("disjoint.in","r",stdin);
    freopen("disjoint.out","w",stdout);
    scanf("%d %d\n",&n,&m);
    for(x=1;x<=n;x++)
        t[x]=x;
    while(m)
    {
        scanf("%d %d %d\n",&op,&x,&y);
        while(x!=t[x])
            x=t[x];
        while(y!=t[y])
            y=t[y];
        if(op==1 && x!=y)
            t[y]=x;
        else
            if(op==2)
                if(x==y)
                    printf("DA\n");
                else
                    printf("NU\n");
        m--;
    }
    return 0;
}