Pagini recente » Cod sursa (job #1075070) | Rating Niculescu Radu (Vladu) | Profil danijura | Cod sursa (job #1153142) | Cod sursa (job #2815883)
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int sef[100001];
int sefm(int x) {
if (sef[x] == x)
return x;
return sef[x] = sefm(sef[x]);
}
void unire (int x, int y) {
int sefx, sefy;
sefx = sefm(x);
sefy = sefm(y);
sef[sefx] = sefy;
}
int main()
{
int n, k, tip, x, y, i;
fin>>n>>k;
for ( i = 1; i <= n; i++)
sef[i] = i;
for (i=1;i<=k;i++) {
fin>>tip>>x>>y;
if (tip == 1)
unire(x, y);
else {
if (sefm(x) == sefm(y))
fout<<"DA\n";
else
fout<<"NU\n";
}
}
}