Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #1235413) | Cod sursa (job #1235434) | Cod sursa (job #1235424)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
#define cout g
#define nmax 100010
int n,m,i,x,y,tip;
int T[nmax];
inline int rad(int x)
{
while (x!=T[x]) x=T[x];
return x;
}
int main()
{
f>>n>>m;
for(i=1;i<=n;++i) T[i]=i;
for(;m;--m)
{
f>>tip>>x>>y;
if(tip==1) T[rad(x)]=rad(y);
else if(rad(x)==rad(y)) cout<<"DA\n";
else cout<<"NU\n";
}
return 0;
}