Pagini recente » Cod sursa (job #2678805) | Cod sursa (job #585741) | Cod sursa (job #2306613) | Cod sursa (job #595646) | Cod sursa (job #1506577)
#include <bits/stdc++.h>
using namespace std;
int n,m,t[100003];
inline int Find(int x)
{
int y,z;
y=x;
while(t[x]!=0)
x=t[x];
while(y!=x)
{
z=t[y];
t[y]=x;
y=z;
}
return x;
}
inline void Union(int x,int y)
{
t[x]=y;
}
inline void Citire()
{
int i,x,y,op,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)
{
if(x!=y)
{
a=Find(x);
b=Find(y);
if(a!=b) Union(a,b);
}
}
else
{
a=Find(x);
b=Find(y);
if(a!=b) fout<<"NU\n";
else fout<<"DA\n";
}
}
fin.close();
fout.close();
}
int main()
{
Citire();
return 0;
}