Pagini recente » Cod sursa (job #1803522) | Cod sursa (job #1431511) | Cod sursa (job #1971125) | Cod sursa (job #1779410) | Cod sursa (job #2651065)
#include <fstream>
using namespace std;
int t[100005],h[100005];
int ft(int x)
{
int c=t[x],res=x;
while(c!=0)
{
res=c;
c=t[c];
}
if(t[x]!=0)
t[x]=res;
return res;
}
void connect(int x,int y)
{
int n,m;
n=ft(x);
m=ft(y);
t[m]=n;
}
int main()
{
ifstream cin("disjoint.in");
ofstream cout("disjoint.out");
int n,m,cd,x,y;
cin >> n >> m;
for(int i=0;i<m;i++)
{
cin >> cd >> x >> y;
if(cd==1)
{
connect(x,y);
}
else
{
if(ft(x)==ft(y))
cout << "DA" << '\n';
else
cout << "NU" << '\n';
}
}
return 0;
}