Pagini recente » Cod sursa (job #1764206) | Cod sursa (job #4053) | Cod sursa (job #2480152) | Cod sursa (job #766865) | Cod sursa (job #3272104)
#include <bits/stdc++.h>
using namespace std;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int t[1005],n,m,o,x,y;
void op1(int x,int y)
{
t[y]=x;
}
int r(int a)
{
if(t[a]!=0)
return r(t[a]);
return a;
}
void op2(int x,int y)
{
if(r(x)==r(y))
out<<"DA\n";
else
out<<"NU\n";
}
int main()
{
in>>n>>m;
for(int i=1;i<=m;i++)
{
in>>o>>x>>y;
if(o==1) op1(x,y);
else op2(x,y);
}
return 0;
}