Advertisement
PikMike

Untitled

Oct 31st, 2016
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. vector<pii> dif;
  2. vector<char> used;
  3.  
  4.  
  5. int findP(int a, vector<int> &p, bool fl){
  6.     if (p[a] == a)
  7.         return a;
  8.     int cur = findP(p[a], p, fl);
  9.     if (fl && p[a] != cur)
  10.         if (!used[a]){
  11.             dif.pb(mp(a, p[a]));
  12.             used[a] = 1;
  13.         }
  14.     return p[a] = cur;
  15. }
  16.  
  17.  
  18. void mergeSt(int a, int b, vector<int> &p, vector<int> &s, bool fl){
  19.     a = findP(a, p, fl);
  20.     b = findP(b, p, fl);
  21.     if (s[a] > s[b])
  22.         swap(a, b);
  23.     if (fl && p[a] != b)
  24.         if (!used[a]){
  25.             dif.pb(mp(a, p[a]));
  26.             used[a] = 1;
  27.         }
  28.     p[a] = b;
  29.     s[b] += s[a];
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement