Pagini recente » Cod sursa (job #548708) | Cod sursa (job #878865) | Cod sursa (job #3178402) | Cod sursa (job #2060923) | Cod sursa (job #2329894)
#include <iostream>
#include <fstream>
#define MAX 100001
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, m;
int tata[MAX];
int findset(int x)
{
if (tata[x] != x)
tata[x] = findset(tata[x]);
return tata[x];
}
int main()
{
fin >> n >> m;
for (int i = 1; i <= n; i++)
tata[i] = i;
while (m--)
{
int p, x, y;
fin >> p >> x >> y;
if (p == 1)
{
tata[findset(y)] = findset(x);
}
else
{
if (findset(x) == findset(y))
fout << "DA\n";
else
fout << "NU\n";
}
}
return 0;
}