Advertisement
nq1s788

снм

Mar 9th, 2024 (edited)
950
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<bitset>
  4. #include<cmath>
  5. #include<deque>
  6. #include<iomanip>
  7. #include <cassert>
  8. #include<list>
  9. #include<vector>
  10. #include<map>
  11. #include<string>
  12. #include<complex>
  13.  
  14. using namespace std;
  15.  
  16. vector<int> t; //t[i] = i
  17. vector<int> h; //высота дерева, h[i] = 1
  18.  
  19. int get(int x) {
  20.     if (t[x] == x) {
  21.         return x;
  22.     }
  23.     return t[x] = get(t[x]);
  24. }
  25.  
  26. void upd(int x, int y) {
  27.     x = get(x);
  28.     y = get(y);
  29.     if (h[x] > h[y]) {
  30.         swap(x, y);
  31.     }
  32.     t[x] = y;
  33.     if (h[x] != h[y]) h[y]++;
  34. }
  35.  
  36. int main() {
  37.    
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement