Cod sursa(job #2976626)
| Utilizator | Data | 9 februarie 2023 19:30:10 | |
|---|---|---|---|
| Problema | Paduri de multimi disjuncte | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.65 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream f("file.in");
//ifstream f("ciur.in");
//ofstream g("ciur.out");
int t[100001], n, q;
int getRoot(int n) {
if(t[n] == n)
return n;
t[n] = getRoot(t[n]);
return t[n];
}
int main(){
f>>n>>q;
for(int i=1; i<=n; i++)
t[i]=i;
while(q) {
int x, y, cer;
f>>cer>>x>>y;
int rx = getRoot(x);
int ry = getRoot(y);
if(cer == 1) {
t[rx] = ry;
}
else {
if(rx == ry)
cout<<"DA"<<'\n';
else
cout<<"NU"<<'\n';
}
q--;
}
return 0;
}