Pagini recente » Cod sursa (job #800699) | Cod sursa (job #355287) | Cod sursa (job #8383) | Cod sursa (job #2544681) | Cod sursa (job #1590368)
#include <iostream>
#include <fstream>
#define maxn 100005
using namespace std;
int main()
{int n,m,i,j,gr[maxn],c,x,y,h[maxn];
fstream f("disjoint.in",ios::in);
fstream g("disjoint.out",ios::out);
f>>n>>m;
for(i=1;i<=n;i++)
{gr[i]=0;h[i]=0;}
for(i=1;i<=m;i++)
{f>>c>>x>>y;
if(c==1)
{while(gr[x]!=0)
x=gr[x];
while(gr[y]!=0)
y=gr[y];
gr[x]=y;
}
else
{while(gr[x]!=0)
x=gr[x];
while(gr[y]!=0)
y=gr[y];
if(x==y)
g<<"DA";
else
g<<"NU";
}
}
g.close();
}