File tree Expand file tree Collapse file tree 1 file changed +4
-10
lines changed
Expand file tree Collapse file tree 1 file changed +4
-10
lines changed Original file line number Diff line number Diff line change 11#pragma once
22struct dsu_weighted {
3- int n;
43 vi p;
54 vector<ll> d;
6- dsu_weighted (int n): n(n), p(n, -1 ), d(n) {}
5+ dsu_weighted (int n): p(n, -1 ), d(n) {}
76 int f (int u) {
87 if (p[u] < 0 ) return u;
98 int root = f (p[u]);
10- d[u] += d[p[u]];
11- return p[u] = root;
9+ return d[u] += d[p[u]], p[u] = root;
1210 }
1311 int size (int u) { return -p[f (u)]; }
1412 ll diff (int u, int v) {
1513 return f (u) == f (v) ? d[v] - d[u] : 1e18 ;
1614 }
1715 bool join (int u, int v, ll w) {
1816 w += d[u] - d[v];
19- u = f (u), v = f (v);
20- if (u == v) return 0 ;
17+ if ((u = f (u)) == (v = f (v))) return 0 ;
2118 if (p[u] > p[v]) swap (u, v), w = -w;
22- p[u] += p[v];
23- p[v] = u;
24- d[v] = w;
25- return 1 ;
19+ return p[u] += p[v], p[v] = u, d[v] = w, 1 ;
2620 }
2721};
You can’t perform that action at this time.
0 commit comments