Pagini recente » Cod sursa (job #263575) | Cod sursa (job #2834266) | Cod sursa (job #180786) | Cod sursa (job #2074361) | Cod sursa (job #2304029)
#include <fstream>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
int n, t[100001], m, x, y, a, b, cod, i;
int rad(int nod){
while(t[nod] > 0)
nod = t[nod];
return nod;
}
int main(){
fin>>n>>m;
for(i=1;i<=n;i++)
t[i] = -1;
while(m--){
fin>>cod>>x>>y;
a = rad(x);
b = rad(y);
if(cod == 1 && a != b){
if(t[a] < t[b]){
t[a] += t[b];
t[b] = a;
}
else{
t[b] += t[a];
t[a] = b;
}
}
if(cod == 2){
if(a == b)
fout<<"DA\n";
else
fout<<"NU\n";
}
}
return 0;
}