Pagini recente » Cod sursa (job #2320756) | Cod sursa (job #2491603) | Cod sursa (job #2301777) | Cod sursa (job #1024608) | Cod sursa (job #2973411)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, m, t[100001];
int cauta(int x)
{
while (t[x] > 0)
x = t[x];
return x;
}
int main()
{
int x, y, i, cod;
fin >> n >> m;
for (i = 1; i <= n; i++)
t[i] = -1;
for (i = 1; i <= m; i++) {
fin >> cod >> x >> y;
x = cauta(x);
y = cauta(y);
if (cod == 1) {
if (-t[x] > -t[y]) {
t[x] += t[y];
t[y] = x;
}
else {
t[y] += t[x];
t[x] = y;
}
}
else {
if (x == y)
fout<<"DA\n";
else
fout<<"NU\n";
}
}
return 0;
}