Pagini recente » Cod sursa (job #2753909) | Cod sursa (job #1248039) | Monitorul de evaluare | Cod sursa (job #1525648) | Cod sursa (job #2199819)
#include <fstream>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
const int N = 100010;
int n,m,o,x,y,T[N],rx,ry,get_root(int);
int main()
{
f>>n>>m;
for(int i=1;i<=n;i++)
T[i]=i;
for(int i=1;i<=m;i++)
{
f>>o>>x>>y;
rx=get_root(x);
ry=get_root(y);
if(o==1)
T[rx]=ry;
else
{
if(rx==ry)
g<<"DA\n";
else
g<<"NU\n";
}
}
return 0;
}
int get_root(int nod)
{
if(T[nod]==nod)
return nod;
T[nod]=get_root(T[nod]);
return T[nod];
}