Pagini recente » Cod sursa (job #2719131) | Cod sursa (job #751892) | Cod sursa (job #2655672) | Cod sursa (job #898358) | Cod sursa (job #507937)
Cod sursa(job #507937)
#include<fstream>
using namespace std;
int t[100000],n,m;
int tt(int a)
{
while (t[a]!=a)
a=t[a];
return a;
}
int main()
{
int i,j,x,y,op;
ifstream in("disjoint.in");
ofstream out("disjoint.out");
in>>n>>m;
for (i=1;i<=n;i++)
t[i]=i;
for (i=1;i<=m;i++)
{
in>>op>>x>>y;
if (op==1)
{
y=tt(y);
x=tt(x);
t[y]=x;
}
else if (op==2)
{
if (tt(x)!=tt(y))
out<<"NU\n";
else
out<<"DA\n";
}
}
}