Pagini recente » Cod sursa (job #1092212) | Cod sursa (job #2056329) | Cod sursa (job #2954487) | Cod sursa (job #2083652) | Cod sursa (job #1954562)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int const penis=1e5;
int N, M, root[penis], op, x, y;
int getRoot(int nod){
if(root[nod]!=nod)
root[nod]=getRoot(root[nod]);
return root[nod];
}
void connectNodes(int x, int y){
x=getRoot(x);
y=getRoot(y);
root[x]=root[y];
}
void checkRoot(int x, int y){
x=getRoot(x);
y=getRoot(y);
if(x==y)
fout<<"DA\n";
else
fout<<"NU\n";
}
int main(){
fin>>N>>M;
for(int i=1; i<=N; i++)
root[i]=i;
for(;M;M--){
fin>>op>>x>>y;
if(op==1)
connectNodes(x,y);
else
checkRoot(x,y);
}
}