Submission #953504

#TimeUsernameProblemLanguageResultExecution timeMemory
953504eysbutnoRailway (BOI17_railway)C++11
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define all(x) begin(x), end(x) #define sz(x) (int) (x).size() #define f first #define s second template<class T> bool smin(T& a, T b) { return b < a ? a = b, 1 : 0; } template<class T> bool smax(T& a, T b) { return b > a ? a = b, 1 : 0; } template<class T> class FenwickTree { private: int sz; vector<T> arr; public: FenwickTree(int n) { sz = n + 1, arr.resize(n + 1); } FenwickTree() {} // empty init T prefix(int idx) { T tot = 0; for (++idx; idx >= 1; idx -= idx & -idx) { tot += arr[idx]; } return tot; } T query(int l, int r) { return prefix(r) - prefix(l - 1); } void update(int idx, T dx) { for (++idx; idx < sz; idx += idx & -idx) { arr[idx] += dx; } } }; void solve() { int n, m, k; cin >> n >> m >> k; vector<vector<pii>> adj(n); for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; adj[--u].push_back({--v, i}); adj[v].push_back({u, i}); } int timer = 0, LOG = 17; vector<int> tin(n), tout(n), taken(n); vector up(LOG, vector(n, 0)); auto tour = [&](int u, int p, auto&& tour) -> void { tin[u] = timer++; for (int i = 1; i < LOG; i++) { up[i][u] = up[i - 1][up[i - 1][u]]; } for (auto [v, id] : adj[u]) if (v != p) { // might need more stuff, just this for now. up[0][v] = u, taken[v] = id; tour(v, u, tour); } tout[u] = timer - 1; }; tour(0, -1, tour); auto isAncestor = [&](int a, int b) -> bool { return tin[a] <= tin[b] && tout[a] >= tout[b]; }; auto lca = [&](int u, int v) -> int { if (isAncestor(u, v)) return u; for (int i = LOG - 1; i >= 0; i--) { if (!isAncestor(up[i][u], v)) { u = up[i][u]; } } return up[0][u]; }; FenwickTree<int> added(timer); for (int i = 0; i < m; i++) { int z; cin >> z; vector<int> cur(z); for (int &i : cur) { cin >> i, --i; } sort(all(cur), [&](int x, int y) { return tin[x] < tin[y]; }); cur.push_back(cur[0]); for (int j = 0; j < z; j++) { int anc = lca(cur[j], cur[j + 1]); added.update(tin[cur[j]], 1); added.update(tin[cur[j + 1]], 1); added.update(tin[anc], -2); } } vector<int> res; for (int i = 1; i < n; i++) { if (added.query(tin[i], tout[i]) >= k * 2) { res.push_back(taken[i]); } } sort(all(res)); cout << sz(res) << "\n"; for (int i = 0; i < sz(res); i++) { cout << res[i] << " \n"[i == sz(res) - 1]; } } int main() { cin.tie(0) -> sync_with_stdio(0); int t = 1; // cin >> t; while (t--) solve(); }

Compilation message (stderr)

railway.cpp: In function 'void solve()':
railway.cpp:52:12: error: missing template arguments before 'up'
   52 |     vector up(LOG, vector(n, 0));
      |            ^~
railway.cpp:53:35: error: use of 'auto' in lambda parameter declaration only available with '-std=c++14' or '-std=gnu++14'
   53 |     auto tour = [&](int u, int p, auto&& tour) -> void {
      |                                   ^~~~
railway.cpp: In lambda function:
railway.cpp:56:13: error: 'up' was not declared in this scope; did you mean 'u'?
   56 |             up[i][u] = up[i - 1][up[i - 1][u]];
      |             ^~
      |             u
railway.cpp:58:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   58 |         for (auto [v, id] : adj[u]) if (v != p) {
      |                   ^
railway.cpp:60:13: error: 'up' was not declared in this scope; did you mean 'u'?
   60 |             up[0][v] = u, taken[v] = id;
      |             ^~
      |             u
railway.cpp:61:28: error: expression cannot be used as a function
   61 |             tour(v, u, tour);
      |                            ^
railway.cpp: In function 'void solve()':
railway.cpp:64:24: error: no match for call to '(solve()::<lambda(int, int, int&&)>) (int, int, solve()::<lambda(int, int, int&&)>&)'
   64 |     }; tour(0, -1, tour);
      |                        ^
railway.cpp:53:17: note: candidate: 'solve()::<lambda(int, int, int&&)>'
   53 |     auto tour = [&](int u, int p, auto&& tour) -> void {
      |                 ^
railway.cpp:53:17: note:   no known conversion for argument 3 from 'solve()::<lambda(int, int, int&&)>' to 'int&&'
railway.cpp: In lambda function:
railway.cpp:71:29: error: 'up' was not declared in this scope; did you mean 'u'?
   71 |             if (!isAncestor(up[i][u], v)) {
      |                             ^~
      |                             u
railway.cpp:75:16: error: 'up' was not declared in this scope; did you mean 'u'?
   75 |         return up[0][u];
      |                ^~
      |                u