Pagini recente » Cod sursa (job #1505232) | Cod sursa (job #571464) | Cod sursa (job #1938239) | Cod sursa (job #1542632) | Cod sursa (job #2073125)
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream input("disjoint.in");
ofstream output("disjoint.out");
int n, m;
input >> n >> m;
int* points = new int[n];
for (int i = 0; i < n; ++i) {
points[i] = i + 1;
}
int order, from, to;
for (int i = 0; i < m; ++i) {
input >> order >> from >> to;
if (order == 1) {
if (points[from - 1] != points[to - 1]) {
if (!points[from - 1]) {
points[from - 1] = points[to - 1];
}
else {
if (!points[to - 1]) {
points[to - 1] = points[from - 1];
}
else {
int temp = points[to - 1];
for (int j = 0; j < n; ++j) {
if (points[j] == temp) {
points[j] = points[from - 1];
}
}
}
}
}
}
else {
if (points[from - 1] == points[to - 1]) {
output << "DA" << endl;
}
else {
output << "NU" << endl;
}
}
}
delete[] points;
input.close();
output.close();
return 0;
}