Cod sursa(job #1469020)

Utilizator vladttturcuman vlad vladtt Data 7 august 2015 15:17:28
Problema Paduri de multimi disjuncte Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <fstream>

using namespace std;

ifstream fin("disjoint.in");
ofstream fout("disjoint.out");

int parent[100100];
int type,x,y,n,i,m;

int link(int child)
{
    if(parent[child]==0)
        return child;
    return parent[child]=link(parent[child]);
}

void link(int a,int b)
{
        parent[link(b)]=link(a);

 }

string check(int x,int y)
{
    if(link(x)==link(y))
        return "DA";
    return "NU";
}

int main()
{
    fin>>n>>m;

    for(i=1;i<=m;i++)
    {
        fin>>type>>x>>y;

        if(x==1 && y==65)
            int ok=1;

        if(type==1)
            link(x,y);
        if(type==2)
            fout<<check(x,y)<<'\n';
    }

    return 0;
}