Cod sursa(job #2810922)

Utilizator teofilotopeniTeofil teofilotopeni Data 30 noiembrie 2021 17:08:43
Problema Paduri de multimi disjuncte Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 kb
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

vector<int> nodes[100001];

int last(int i) {
	if (nodes[i].size()) {
		return last(nodes[i][0]);
	}
	return i;
}

int main() {
	freopen("disjoint.in", "r", stdin);
	freopen("disjoint.out", "w", stdout);
	int nr, operations;
	cin >> nr >> operations;
	while (operations--) {
		int cod, x, y;
		cin >> cod >> x >> y;
		if (cod == 1) {
			nodes[last(x)].push_back(y);
		}
		else {
			string answer[] = { "NU\n", "DA\n" };
			cout << answer[last(x) == last(y)];
		}
	}
	return 0;
}