Submission #1085320

#TimeUsernameProblemLanguageResultExecution timeMemory
1085320eysbutnoBitaro’s Party (JOI18_bitaro)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = array<int, 2>; #define all(x) begin(x), end(x) #define sz(x) (int) (x).size() constexpr int B = 45; int main() { cin.tie(0) -> sync_with_stdio(0); int n, m, q; cin >> n >> m >> q; vector<vector<int>> adj(n); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; --u, --v; adj[u].push_back(v); } vector<int> mp(n, -1); vector<vector<pii>> best(n); const auto merge = [&](int from, int to) -> void { vector<int> seen; for (auto [node, dist] : best[from]) { mp[node] = max(mp[node], dist + 1); seen.push_back(node); } for (auto [node, dist] : best[to]) { mp[node] = max(mp[node], dist); seen.push_back(node); } best[to].clear(); for (auto [node, dist] : mp) { best[to].push_back({node, dist}); } sort(all(best[to]), [&](auto &x, auto &y) -> bool { return x[1] > y[1]; }); if (sz(best[to]) > B) { best[to].resize(B); } for (int x : seen) { mp[x] = -1; } }; for (int u = 0; u < n; u++) { if (sz(best[u]) < B) { best[u].push_back({u, 0}); } for (int v : adj[u]) { merge(u, v); } } const auto check = [&](int t, const set<int> &bad) -> int { for (auto [node, dist] : best[t]) { if (!bad.count(node)) { return dist; } } return -1; }; const auto brute_force = [&](int t, const set<int> &bad) -> int { vector<int> opt(n, -1); for (int u = 0; u <= t; u++) { if (!bad.count(u)) { opt[u] = max(0, opt[u]); } for (int v : adj[u]) { if (opt[u] != -1) { opt[v] = max(opt[v], opt[u] + 1); } } } return opt[t]; }; while (q--) { int t, y; cin >> t >> y; --t; set<int> bad; for (int i = 0; i < y; i++) { int x; cin >> x; bad.insert(--x); } if (y >= B) { cout << brute_force(t, bad) << "\n"; } else { cout << check(t, bad) << "\n"; } } /* for (int i = 0; i < n; i++) { cout << "node " << i + 1 << "\n"; for (auto [node, dist] : best[i]) { cout << node + 1 << " " << dist << "\n"; } } */ }

Compilation message (stderr)

bitaro.cpp: In lambda function:
bitaro.cpp:33:19: error: cannot decompose non-array non-class type 'int'
   33 |         for (auto [node, dist] : mp) {
      |                   ^~~~~~~~~~~~
bitaro.cpp:34:44: error: no matching function for call to 'std::vector<std::array<int, 2> >::push_back(<brace-enclosed initializer list>)'
   34 |             best[to].push_back({node, dist});
      |                                            ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from bitaro.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::array<int, 2>; _Alloc = std::allocator<std::array<int, 2> >; std::vector<_Tp, _Alloc>::value_type = std::array<int, 2>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::array<int, 2>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::array<int, 2>; _Alloc = std::allocator<std::array<int, 2> >; std::vector<_Tp, _Alloc>::value_type = std::array<int, 2>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::array<int, 2> >::value_type&&' {aka 'std::array<int, 2>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~