Pagini recente » Istoria paginii utilizator/pufosenie | Cod sursa (job #654076) | Cod sursa (job #313638) | Cod sursa (job #893574) | Cod sursa (job #1497019)
#include <bits/stdc++.h>
using namespace std;
int v[100005];
int first(int a) {
a = v[a];
while(a != v[a])
a = v[a];
return a;
}
void mergeList(int a, int b) {
int A = first(a);
int B = first(b);
v[A] = v[B];
}
int main()
{
ios::sync_with_stdio(false);
ifstream cn("disjoint.in");
ofstream co("disjoint.out");
int n, m;
int x, y, t;
cn >> n >> m;
for(int i = 1; i <= n; i ++) {
v[i] = i;
}
for(int i = 1; i <= m; i ++) {
cn >> t >> x >> y;
if(t == 1) mergeList(x, y);
else {
if(first(x) == first(y))
co << "DA\n";
else
co << "NU\n";
}
}
cn.close();
co.close();
return 0;
}