Pagini recente » Cod sursa (job #2407260) | Cod sursa (job #2373482) | Cod sursa (job #2327610) | Cod sursa (job #2545711) | Cod sursa (job #2978953)
#include <bits/stdc++.h>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
const int N = 100010;
int n,m,T[N];
int getRoot(int nod)
{
if(T[nod]==nod)
return nod;
T[nod]=getRoot(T[nod]);
return T[nod];
}
int main()
{
f>>n>>m;
for(int i=1;i<=n;i++)
T[i]=i;
for(int i=1;i<=m;i++)
{
int tip,x,y;
f>>tip>>x>>y;
int rx=getRoot(x);
int ry=getRoot(y);
if(tip==1)
{
/// reuneste multimile Mx si My
T[rx]=ry;
}
else
{
/// afiseaza 1/0 daca x si y sunt/nu sunt in aceeasi multime
if(rx==ry)
g<<"DA\n";
else
g<<"NU\n";
}
}
return 0;
}