Cod sursa(job #1350312)

Utilizator RazvanBawsRazvan Radoi RazvanBaws Data 20 februarie 2015 19:07:56
Problema Paduri de multimi disjuncte Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
#include <fstream>

using namespace std;
const int nmax = 100001;
int t[nmax],h[nmax];
int findset(int x)
{
    while(t[x]!=x)
    {
        x=t[x];
        return x;
    }
}
int main()
{
    ifstream in("disjoint.in");
    ofstream out("disjoint.out");
    int n,m,i,op,x,y,tx,ty;
    in>>n>>m;
    for(i=1; i<=n; i++)
    {
        t[i]=i;
        h[i]=1;
    }
    for(i=1; i<=m; i++)
    {
        in>>op>>x>>y;
        if(op==2)
            tx=findset(x);
        ty=findset(y);
        if(tx==ty)
            out<<"DA"<<endl;
        else
            out<<"NU"<<endl;
    }
    in.close();
    out.close();
    return 0;
}