Pagini recente » Cod sursa (job #32861) | Cod sursa (job #283277) | Cod sursa (job #1868810) | Cod sursa (job #893266) | Cod sursa (job #2200703)
#include <iostream>
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int n, m, t[100002];
int tata(int x)
{
if(t[x]!=x)
t[x]=tata(t[x]);
return t[x];
}
/*inline void compresie(int x, int r)
{
int cx;
while(t[x]!=x)
{
cx=t[x];
t[x]=r;
x=cx;
}
}*/
int main()
{
int op, x, y, r;
f>>n>>m;
for(int i=1;i<=n;i++)
t[i]=i;
while(f>>op>>x>>y)
{
if(op==1)
{
x=tata(x);
y=tata(y);
t[x]=y;
}
else
{
r=tata(x);
//compresie(x, r);
if(r==tata(y))
g<<"DA\n";
else
g<<"NU\n";
}
}
return 0;
}