Pagini recente » Cod sursa (job #2147950) | Cod sursa (job #2727967) | Cod sursa (job #2541729) | Cod sursa (job #752475) | Cod sursa (job #2048310)
#include <fstream>
#define N 100010
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int tata[N],x,y,q,rootx,rooty,get_root(int),n,m;
int main()
{
fin>>n>>m;
for(int i=1;i<=n;i++)tata[i]=i;
for(;m;m--)
{
fin>>q>>x>>y;
rootx=get_root(x);
rooty=get_root(y);
if(q==1)
tata[rootx]=rooty;
else rootx==rooty?fout<<"DA\n":fout<<"NU\n";
}
return 0;
}
int get_root(int nod)
{
if(tata[nod]==nod)return nod;
tata[nod]=get_root(tata[nod]);
return tata[nod];
}