Pagini recente » Cod sursa (job #56541) | Cod sursa (job #2175001) | Cod sursa (job #1810117) | Cod sursa (job #2863010) | Cod sursa (job #2042173)
#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 100000 + 5;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int t[N_MAX], n, m;
int tata(int nod){
if (t[nod] == nod)
return nod;
t[nod] = tata(t[nod]);
return t[nod];
}
void uneste(int a, int b){
t[tata(b)] = t[a];
}
int main()
{
fin >> n >> m;
for(int i = 1; i<=n; ++i)
t[i] = i;
while(m--){
int tip, a, b; fin >> tip >> a >> b;
if(tip == 1)
if(tata(a) != tata(b))
uneste(a,b);
if(tip == 2)
if(tata(a) == tata(b))
fout << "DA\n";
else fout << "NU\n";
}
return 0;
}