diff options
author | Anthony Wang | 2020-10-20 22:03:13 -0500 |
---|---|---|
committer | Anthony Wang | 2020-10-20 22:03:13 -0500 |
commit | ebf0e5d4db0f9973a373846ff5053f6ddc51f587 (patch) | |
tree | 0b55dc0a2d42b6a0a331f6a91cb0d6eed5a214d8 | |
parent | 9f12bd037f1ecc1b0cc9cd6271a953e3011cbb19 (diff) |
Enforce consistent style
-rw-r--r-- | Graph/lca.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/Graph/lca.cpp b/Graph/lca.cpp index 38d972e..b6d695f 100644 --- a/Graph/lca.cpp +++ b/Graph/lca.cpp @@ -1,17 +1,17 @@ namespace lca { - int d[MX], L[MX][20]; - void dfs(vector<int> * G, int u = 1, int p = 0) { - d[u] = d[p] + 1, L[u][0] = p; - for (int i = 0; i < 18 && L[u][i]; i++) L[u][i + 1] = L[L[u][i]][i]; - for (auto& v : G[u]) if (v != p) dfs(G, v, u); - } - int lca(vector<int> * G, int u, int v) { - if (d[u] > d[v]) swap(u, v); - for (int i = 18; i >= 0; --i) if (d[v] - (1 << i) >= d[u]) v = L[v][i]; - if (u == v) return u; - for (int i = 18; i >= 0; --i) if (L[u][i] && L[u][i] != L[v][i]) u = L[u][i], v = L[v][i]; - return L[u][0]; - } + int d[MX], L[MX][20]; + void dfs(vector<int> * G, int u = 1, int p = 0) { + d[u] = d[p] + 1, L[u][0] = p; + for (int i = 0; i < 18 && L[u][i]; i++) L[u][i + 1] = L[L[u][i]][i]; + for (auto & v : G[u]) if (v != p) dfs(G, v, u); + } + int lca(vector<int> * G, int u, int v) { + if (d[u] > d[v]) swap(u, v); + for (int i = 18; i >= 0; --i) if (d[v] - (1 << i) >= d[u]) v = L[v][i]; + if (u == v) return u; + for (int i = 18; i >= 0; --i) if (L[u][i] && L[u][i] != L[v][i]) u = L[u][i], v = L[v][i]; + return L[u][0]; + } inline int dist(vector<int> * G, int u, int v) { return d[u]+d[v]-2*d[lca(G, u, v)]; } |