Pagini recente » Borderou de evaluare (job #201317) | Cod sursa (job #139423) | Cod sursa (job #425193) | Cod sursa (job #640882) | Cod sursa (job #2651060)
#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];
t[x]=c;
}
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;
}