Pagini recente » Cod sursa (job #692430) | Cod sursa (job #2506174) | Cod sursa (job #1458899) | Cod sursa (job #2910959) | Cod sursa (job #3156337)
#include <bits/stdc++.h>
using namespace std;
int parent[100005];
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int root (int x){
if (parent[x]==x)
return x;
return parent[x] = root(parent[x]);
}
void unite (int x, int y){
auto root1 = root(x);
auto root2 = root(y);
parent[root2] = root1;
}
void solve_query (){
int tip, x, y;
fin >> tip >> x >> y;
if(tip == 1)
unite(x, y);
else
fout << (root(x) == root(y)? "DA" : "NU") << "\n";
}
int main(){
int n, q;
fin >> n >> q;
for (int i=1; i<=n; i++)
parent[i] = i;
while (q--)
solve_query();
return 0;
}