Skip to content

Commit b04851b

Browse files
committed
nits
1 parent ff72553 commit b04851b

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#pragma once
2+
//! https://codeforces.com/blog/entry/125018
3+
//! @code
4+
//! vector<basic_string<int>> adj(n);
5+
//! shallowest(adj, [&](int cent) {
6+
//! });
7+
//! @endcode
8+
//! @time O(n log n)
9+
//! @space O(n)
210
void shallowest(auto& adj, auto f) {
311
vector<vi> order(bit_width(size(adj)));
412
auto dfs = [&](auto&& self, int v, int p) -> int {
@@ -13,13 +21,11 @@ void shallowest(auto& adj, auto f) {
1321
return dp;
1422
};
1523
dfs(dfs, 0, 0);
16-
for (auto& vec : order | views::reverse)
17-
for (int cent : vec) {
18-
f(cent);
19-
for (int v : adj[cent]) {
20-
iter_swap(ranges::find(adj[v], cent),
21-
rbegin(adj[v]));
22-
adj[v].pop_back();
23-
}
24+
for (const auto& vec : order | views::reverse)
25+
for (int v : vec) {
26+
f(v);
27+
for (int u : adj[v])
28+
iter_swap(ranges::find(adj[u], v), rbegin(adj[u])),
29+
adj[u].pop_back();
2430
}
2531
}

0 commit comments

Comments
 (0)