Pagini recente » Cod sursa (job #1607251) | Cod sursa (job #1263827) | Cod sursa (job #1515242) | Cod sursa (job #342700) | Cod sursa (job #1394390)
#include <iostream>
#include<fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int n,m,i,t[100001],x,y,cod,tx,ty;
int findt(int x)
{
if(x!=t[x])
return t[x]=findt(t[x]);
else return x;
}
void unite(int x,int y)
{
tx=findt(x);
ty=findt(y);
t[tx]=ty;
}
int main()
{
f>>n>>m;
for(i=1;i<=n;i++)
t[i]=i;
for(i=1;i<=m;i++)
{
f>>cod>>x>>y;
if(cod==1) unite(x,y);
else if(findt(x)==findt(y)) g<<"DA"<<endl;
else g<<"NU"<<endl;
}
return 0;
}