Submission #997327

#TimeUsernameProblemLanguageResultExecution timeMemory
997327goats_9Railway (BOI17_railway)C++17
36 / 100
72 ms27336 KiB
/* Author: goats_9 */ #include <bits/stdc++.h> using namespace std; using ll = long long; const int LOG = 18; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, k; cin >> n >> m >> k; vector<int> depth(n + 1), maj(n + 1), ans(n); vector<array<int, 2>> edges(n); vector<vector<array<int, 2>>> adj(n + 1, vector<array<int, 2>>()); vector<array<int, LOG>> par(n + 1); for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; edges[i] = {u, v}; adj[u].push_back({v, i}); adj[v].push_back({u, i}); } function<void(int, int)> dfs = [&] (int u, int p) { par[u][0] = p; for (int i = 1; i < LOG; i++) par[u][i] = par[par[u][i - 1]][i - 1]; depth[u] = depth[p] + 1; for (auto [v, _] : adj[u]) { if (v == p) continue; dfs(v, u); } }; dfs(1, 0); auto lca = [&] (int u, int v) -> int { if (depth[u] > depth[v]) swap(u, v); int d = depth[v] - depth[u]; for (int i = LOG - 1; i >= 0; i--) { if (d&(1<<i)) v = par[v][i]; } if (u == v) return u; for (int i = LOG - 1; i >= 0; i--) { if (par[u][i] != par[v][i]) { u = par[u][i]; v = par[v][i]; } } return par[u][0]; }; function <void(int, int)> dfs2 = [&] (int u, int p) { for (auto [v, j] : adj[u]) { if (v == p) continue; dfs2(v, u); maj[u] += maj[v]; ans[j] += maj[v]; } }; while (m--) { int sz; cin >> sz; set<array<int, 2>> st; while (sz--) { int x; cin >> x; st.insert({depth[x], x}); } while (st.size() > 1) { auto [du, u] = *(--st.end()); st.erase({du, u}); auto [dv, v] = *(--st.end()); st.erase({dv, v}); int w = lca(u, v); ++maj[u], ++maj[v]; maj[w] -= 2; st.insert({depth[w], w}); } } dfs2(1, 0); vector<int> res; for (int i = 1; i < n; i++) { if (ans[i] >= k) res.push_back(i); } cout << res.size() << '\n'; for (auto u : res) cout << u << ' '; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...