Pagini recente » Statistici Liviu Florescu (liviuf) | Cod sursa (job #1921519) | Cod sursa (job #262740) | Cod sursa (job #2071869) | Cod sursa (job #2676940)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin ("disjoint.in");
ofstream fout ("disjoint.out");
int n, m, whichComponent[100001];
int main() {
fin.tie(0);
fout.tie(0);
ios::sync_with_stdio(0);
fin >> n >> m;
int operation, a, b;
for (int i = 1; i <= n; i++)
whichComponent[i] = i;
for (int i = 0; i < m; i++) {
fin >> operation >> a >> b;
if (operation == 1) {
int maxNode = a, minNode = b;
if (whichComponent[a] < whichComponent[b])
swap(minNode, maxNode);
int changeComponent = whichComponent[maxNode];
for (int i = 1; i <= n; i++)
if (whichComponent[i] == changeComponent)
whichComponent[i] = whichComponent[minNode];
}
else if (whichComponent[a] == whichComponent[b])
fout << "DA\n";
else
fout << "NU\n";
}
return 0;
}