Skip to content

Commit d5626d6

Browse files
committed
more golf
1 parent a6babce commit d5626d6

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

library/dsu/dsu_bipartite.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ struct dsu_bipartite {
1313
int size(int v) { return -p[f(v)]; }
1414
bool is_bipartite(int v) { return is_bi[f(v)]; }
1515
bool join(int u, int v) {
16-
int root_u = f(u), root_v = f(v);
16+
int x = f(u), y = f(v);
1717
int new_parity = parity[u] ^ parity[v];
18-
if ((u = root_u) == (v = root_v)) {
19-
is_bi[u] &= new_parity;
18+
if (x == y) {
19+
is_bi[x] &= new_parity;
2020
return 0;
2121
}
22-
if (p[u] > p[v]) swap(u, v);
23-
is_bi[u] &= is_bi[v];
24-
parity[v] = new_parity ^ 1;
25-
p[u] += p[v], p[v] = u;
22+
if (p[x] > p[y]) swap(x, y);
23+
is_bi[x] &= is_bi[y];
24+
parity[y] = new_parity ^ 1;
25+
p[x] += p[y], p[y] = x;
2626
return 1;
2727
}
2828
};

library/dsu/dsu_weighted.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ struct dsu_weighted {
2222
return f(u) == f(v) ? d[v] - d[u] : 1e18;
2323
}
2424
bool join(int u, int v, ll w) {
25-
int root_u = f(u), root_v = f(v);
25+
int x = f(u), y = f(v);
2626
w += d[u] - d[v];
27-
if ((u = root_u) == (v = root_v)) return 0;
28-
if (p[u] > p[v]) swap(u, v), w = -w;
29-
return p[u] += p[v], p[v] = u, d[v] = w, 1;
27+
if (x == y) return 0;
28+
if (p[x] > p[y]) swap(x, y), w = -w;
29+
return p[x] += p[y], p[y] = x, d[y] = w, 1;
3030
}
3131
};

0 commit comments

Comments
 (0)