Pagini recente » Cod sursa (job #1973474) | Cod sursa (job #2227594) | Cod sursa (job #1434288) | Cod sursa (job #6005) | Cod sursa (job #1350312)
#include <fstream>
using namespace std;
const int nmax = 100001;
int t[nmax],h[nmax];
int findset(int x)
{
while(t[x]!=x)
{
x=t[x];
return x;
}
}
int main()
{
ifstream in("disjoint.in");
ofstream out("disjoint.out");
int n,m,i,op,x,y,tx,ty;
in>>n>>m;
for(i=1; i<=n; i++)
{
t[i]=i;
h[i]=1;
}
for(i=1; i<=m; i++)
{
in>>op>>x>>y;
if(op==2)
tx=findset(x);
ty=findset(y);
if(tx==ty)
out<<"DA"<<endl;
else
out<<"NU"<<endl;
}
in.close();
out.close();
return 0;
}