Pagini recente » Cod sursa (job #269560) | Cod sursa (job #3168718) | Cod sursa (job #2934016) | Cod sursa (job #1405148) | Cod sursa (job #3272257)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("disjoint.in");
ofstream fout("disjoint.out");
const int MaxN = 100005;
vector<int>g[MaxN];
int n, m, t[MaxN];
void Union(int x, int y){
t[x] = y;
}
int Find(int x){
int rad = x, y;
while(t[rad] != 0)
rad = t[rad];
while(x != rad){
y = t[x];
t[x] = rad;
x = y;
}
return rad;
}
int main()
{
int x, y, task;
fin >> n >> m;
for(int i = 1; i <= m; i++){
fin >> task >> x >> y;
if(task == 1){
x = Find(x);
y = Find(y);
if(x != y)
Union(x, y);
}
else{
if(Find(x) == Find(y))
fout << "DA\n";
else fout << "NU\n";
}
}
return 0;
}