Pagini recente » Cod sursa (job #1210871) | Cod sursa (job #2535650) | Cod sursa (job #3242646) | Cod sursa (job #2474375) | Cod sursa (job #1838704)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("disjoint.in");
ofstream g("disjoint.out");
int n,m,i,x,y,op,tata[100010],stramos(int);
int main()
{
f>>n>>m;
for(i=1;i<=n;i++)
tata[i]=i;
for(;m;m--)
{
f>>op>>x>>y;
x=stramos(x);
y=stramos(y);
if(op==1)tata[x]=y;
else x==y?g<<"DA\n":g<<"NU\n";
}
return 0;
}
int stramos(int nod)
{
if(tata[nod]==nod)
return nod;
tata[nod]=stramos(tata[nod]);
return tata[nod];
}