We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9bfc7ab commit f862976Copy full SHA for f862976
content/graph/HLD.h
@@ -42,11 +42,11 @@ template <bool VALS_EDGES> struct HLD {
42
}
43
44
template <class B> void process(int u, int v, B op) {
45
- for (; rt[u] != rt[v]; v = par[rt[v]]) {
+ for (;; v = par[rt[v]]) {
46
if (pos[u] > pos[v]) swap(u, v);
47
+ if (rt[u] == rt[v]) break;
48
op(pos[rt[v]], pos[v] + 1);
49
- if (pos[u] > pos[v]) swap(u, v);
50
op(pos[u] + VALS_EDGES, pos[v] + 1);
51
52
void modifyPath(int u, int v, int val) {
0 commit comments