aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2020-08-21 15:17:54 -0500
committerAnthony Wang2020-08-21 15:17:54 -0500
commit0f80ef68d7560daf2bda471b35915f37d43d8b34 (patch)
treeed9d919e9742a958b5f65f7e2c7e0eb5bdcda063
parent0ba24fbd071e3333282837ceeb52e349c8aec183 (diff)
Use struct instead of namespace
-rw-r--r--Graph/centroid.cpp2
-rw-r--r--Graph/lca.cpp30
2 files changed, 15 insertions, 17 deletions
diff --git a/Graph/centroid.cpp b/Graph/centroid.cpp
index 32d5a19..0497bf6 100644
--- a/Graph/centroid.cpp
+++ b/Graph/centroid.cpp
@@ -1,4 +1,4 @@
-namespace centroid {
+struct centroid {
int sz[MN], cpar[MN];
bitset<MN> vis;
void dfs(vector<int> * G, int u, int p = 0) {
diff --git a/Graph/lca.cpp b/Graph/lca.cpp
index 5823f7c..d02598f 100644
--- a/Graph/lca.cpp
+++ b/Graph/lca.cpp
@@ -1,17 +1,15 @@
-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 < 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 = 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];
+struct lca {
+ int d[MN], L[MN][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];
+ }
}