diff options
| author | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-11-16 01:24:14 +0100 |
|---|---|---|
| committer | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-11-16 01:24:14 +0100 |
| commit | 98567ec798aa8ca2cfbcb85c774dd470f30e30d4 (patch) | |
| tree | 5113d5cc24d1ad5f93810b6442ce584a36950dc8 /graph/centroid.cpp | |
| parent | ad3856a6b766087df0036de0b556f4700a6498c9 (diff) | |
| parent | 8d11c6c8213f46f0fa19826917c255edd5d43cb1 (diff) | |
mzuenni tests
Diffstat (limited to 'graph/centroid.cpp')
| -rw-r--r-- | graph/centroid.cpp | 21 |
1 files changed, 0 insertions, 21 deletions
diff --git a/graph/centroid.cpp b/graph/centroid.cpp deleted file mode 100644 index 2494464..0000000 --- a/graph/centroid.cpp +++ /dev/null @@ -1,21 +0,0 @@ -vector<int> s; -void dfs_sz(int v, int from = -1) { - s[v] = 1; - for (int u : adj[v]) if (u != from) { - dfs_sz(u, v); - s[v] += s[u]; -}} - -pair<int, int> dfs_cent(int v, int from, int n) { - for (int u : adj[v]) if (u != from) { - if (2 * s[u] == n) return {v, u}; - if (2 * s[u] > n) return dfs_cent(u, v, n); - } - return {v, -1}; -} - -pair<int, int> find_centroid(int root) { - s.resize(sz(adj)); - dfs_sz(root); - return dfs_cent(root, -1, s[root]); -} |
