Pagini recente » Cod sursa (job #2401084) | Cod sursa (job #1544512) | Cod sursa (job #284843) | Cod sursa (job #2095409) | Cod sursa (job #3192856)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n,m,c,x,y,root[100005],dim[100005];
int getroot(int x)
{
while(root[x]!=0)
x=root[x];
return x;
}
void task(int x,int y)
{
int rootx=getroot(x),rooty=getroot(y);
if(dim[rootx]<dim[rooty])
swap(rootx,rooty);
root[rooty]=rootx;
dim[rootx]+=dim[rooty];
}
int main()
{
fin>>n>>m;
for(int i=1; i<=n; i++)
dim[i]=1;
for(int i=1; i<=m; i++)
{
fin>>c>>x>>y;
if(c==1)
task(x,y);
else if(getroot(x)==getroot(y))
fout<<"DA"<<'\n';
else
fout<<"NU"<<'\n';
}
return 0;
}