Pagini recente » Cod sursa (job #2603744) | Cod sursa (job #555629) | Cod sursa (job #121915) | Cod sursa (job #1155183) | Cod sursa (job #2713741)
#include <fstream>
#define nmax 100005
using namespace std;
ifstream cin ("disjoint.in");
ofstream cout ("disjoint.out");
int v[nmax];
int root(int x)
{
int t=x;
while (v[t]>=0)
t=v[t];
return t;
}
void tie(int a, int b)
{
int x=root(a);
int y=root(b);
if(v[x]>v[y])
swap(x,y);
v[x]+=v[y];
v[y]=x;
}
int query(int a,int b)
{
if (root(a)==root(b))
return 1;
return 0;
}
int main()
{
int n,m;
cin>>n>>m;
for (int i=1; i<=n; i++)
v[i]=-1;
for (int i=1; i<=m; i++)
{
int op,a,b;
cin>>op>>a>>b;
if (op==1)
tie(a,b);
else
{
if (query(a,b)==1)
cout<<"DA\n";
else
cout<<"NU\n";
}
}
}