Pagini recente » Cod sursa (job #2030574) | Cod sursa (job #2212198) | Cod sursa (job #2220324) | Cod sursa (job #1659705) | Cod sursa (job #2852946)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int T[100001];
int n, m, x, y, c, tx, ty;
int det_tata(int x)
{
if(T[x]==0)
{
return x;
}
T[x]=det_tata(T[x]);
return T[x];
}
int main()
{
fin>>n>>m;
for(int i=0; i<m; i++)
{
fin>>c>>x>>y;
tx=det_tata(x);
ty=det_tata(y);
if(c==2)
{
if(tx!=ty)
{
fout<<"NU"<<'\n';
}
else
{
fout<<"DA"<<'\n';
}
}
else
{
T[tx]=ty;
}
}
fin.close();
fout.close();
return 0;
}