Pagini recente » Cod sursa (job #1906121) | Cod sursa (job #3121871) | Cod sursa (job #2495020) | Cod sursa (job #139826) | Cod sursa (job #2291032)
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<vector>
#include<list>
#include <fstream>
#include <iostream>
using namespace std;
#define MAXN 100000
#define MAXM 100000
int M,N;
typedef struct nod{
int parent;
int height;
}nod;
nod A[MAXN+1];
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int findroot(int x){
while(A[x].parent!=0)
x=A[x].parent;
return x;
}
#define maxim(a,b) a>b?a:b
int main(){
fin >> N >> M;
int x,y,cod;
int rx,ry;
for(int i=0;i<M;i++){
fin >> cod >> x >> y;
if(cod==1){
rx=findroot(x);
ry=findroot(y);
if(A[rx].height<A[ry].height){
A[rx].parent=ry;
A[ry].height=maxim(A[ry].height,(A[rx].height+1));
}
else{
A[ry].parent=rx;
A[rx].height=maxim(A[rx].height,(A[ry].height+1));
}
}
else{
rx=findroot(x);
ry=findroot(y);
if(rx==ry)
fout << "DA" << endl;
else
fout << "NU" << endl;
}
}
fin.close();
fout.close();
return 0;
}