diff options
author | Anthony Wang | 2020-08-21 10:46:26 -0500 |
---|---|---|
committer | Anthony Wang | 2020-08-21 10:46:26 -0500 |
commit | d0f1b5990896df00c0414a86f1baf27527865c72 (patch) | |
tree | 8f6f07640c42ef96f44d0ed2d7e86b8d3c9f3947 | |
parent | 29eb7792ce4e2b3f56286e1b145be06b2e2b341a (diff) |
Enforce consistent style
-rw-r--r-- | Graph/lca.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Graph/lca.cpp b/Graph/lca.cpp index 6ca4664..5823f7c 100644 --- a/Graph/lca.cpp +++ b/Graph/lca.cpp @@ -1,17 +1,17 @@ -int d[MAXN], L[MAXN][20]; -vector<int> G[MAXN]; +int d[MN], L[MN][20]; +vector<int> G[MN]; void dfs(int u = 1, int p = 0) { d[u] = d[p] + 1; L[u][0] = p; - for (int i = 0; i < 16 && L[u][i]; i++) L[u][i + 1] = L[L[u][i]][i]; + 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(v, u); } int lca(int u, int v) { if (d[u] > d[v]) swap(u, v); - for (int i = 16; i >= 0; i--) if (d[v] - (1 << i) >= d[u]) v = L[v][i]; + 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 = 16; i >= 0; i--) if (L[u][i] && L[u][i] != L[v][i]) u = L[u][i], v = L[v][i]; + 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]; -}
\ No newline at end of file +} |