Pagini recente » Cod sursa (job #1319171) | Cod sursa (job #2111939) | Cod sursa (job #887281) | Cod sursa (job #2554759) | Cod sursa (job #1795202)
#include <fstream>
#define VAL 100005
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int N, M, i;
int t, x, y;
int dx, dy;
int fat[VAL];
int GetFat(int a)
{
if (fat[a]!=a)
fat[a]=GetFat(fat[a]);
return fat[a];
}
int main()
{
fin >> N >> M;
for (i=1; i<=N; i++)
fat[i]=i;
for (i=1; i<=M; i++)
{
fin >> t >> x >> y;
dx=GetFat(x);
dy=GetFat(y);
if (t==1)
fat[x]=dy;
else
{
if (dx==dy)
fout << "DA\n";
else
fout << "NU\n";
}
}
fin.close();
fout.close();
return 0;
}