Pagini recente » Cod sursa (job #2198663) | Cod sursa (job #645409) | Cod sursa (job #423494) | Cod sursa (job #2902659) | Cod sursa (job #3272105)
#include <bits/stdc++.h>
using namespace std;
ifstream in ("disjoint.in");
ofstream out ("disjoint.out");
int t[100008],n,m,o,x,y;
void op1(int x,int y)
{
t[y]=x;
}
int r(int c)
{
if(t[c]!=0)
return r(t[c]);
return c;
}
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);
if(o==2)
op2(x,y);
}
return 0;
}