Pagini recente » Cod sursa (job #2818531) | Cod sursa (job #946721) | Cod sursa (job #1493784) | Cod sursa (job #1133241) | Cod sursa (job #1874347)
#include <bits/stdc++.h>
using namespace std;
int n,m,op,t[100005];
inline int Find(int x)
{
int c=x;
while(t[x]!=0)
{
x=t[x];
}
return x;
}
inline void Union(int x, int y)
{
t[x]=y;
}
int main()
{
int i,x,y,a,b;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
fin>>n>>m;
for(i=1;i<=m;i++)
{
fin>>op>>x>>y;
if(op==1)
{
a=Find(x);
b=Find(y);
if(a!=b) Union(a,b);
}
else
{
a=Find(x);
b=Find(y);
if(a==b) fout<<"DA\n";
else fout<<"NU\n";
}
}
fin.close();
fout.close();
return 0;
}