Pagini recente » Cod sursa (job #1213972) | Cod sursa (job #755348) | Cod sursa (job #1378271) | Cod sursa (job #2945085) | Cod sursa (job #3128761)
#include <bits/stdc++.h>
#define N 100'005
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n,m,i,op,x,y;
int c[N],r[N];
int look(int x)
{
if(r[x]==x) return x;
r[x]=look(r[x]);
return r[x];
}
int unite(int x,int y)
{
if(c[x]<c[y]) swap(x,y);
c[x]+=c[y];
r[y]=x;
}
int main()
{
fin>>n>>m;
for(i=1;i<=n;++i)
{
c[i]=1;
r[i]=i;
}
for(int w=1;w<=m;++w)
{
fin>>op>>x>>y;
if(op==1) unite(look(x),look(y));
else
{
if(look(x)==look(y)) fout<<"DA\n";
else fout<<"NU\n";
}
}
return 0;
}