Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<algorithm>
- #include<bitset>
- #include<cmath>
- #include<deque>
- #include<iomanip>
- #include <cassert>
- #include<list>
- #include<vector>
- #include<map>
- #include<string>
- #include<complex>
- using namespace std;
- vector<int> t; //t[i] = i
- vector<int> h; //высота дерева, h[i] = 1
- int get(int x) {
- if (t[x] == x) {
- return x;
- }
- return t[x] = get(t[x]);
- }
- void upd(int x, int y) {
- x = get(x);
- y = get(y);
- if (h[x] > h[y]) {
- swap(x, y);
- }
- t[x] = y;
- if (h[x] != h[y]) h[y]++;
- }
- int main() {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement