Submission #642184

#TimeUsernameProblemLanguageResultExecution timeMemory
642184stevancvBitaro’s Party (JOI18_bitaro)C++14
100 / 100
1505 ms414892 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 1e5 + 2; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, q; cin >> n >> m >> q; vector<vector<int>> g(n); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u -= 1; v -= 1; g[v].push_back(u); } const int M = 350; vector<vector<pair<int, int>>> di(n); vector<int> lst(n, -1), dist(n); for (int i = 0; i < n; i++) { vector<int> v; for (int j : g[i]) { for (auto [u, d] : di[j]) { if (lst[u] != i) { dist[u] = d + 1; lst[u] = i; v.push_back(u); } else smax(dist[u], d + 1); } } v.push_back(i); sort(v.begin(), v.end(), [&] (int x, int y) { return dist[x] > dist[y]; }); for (int j = 0; j < min((int) v.size(), M); j++) di[i].push_back({v[j], dist[v[j]]}); } vector<bool> busy(n); while (q--) { int c; cin >> c; c--; int sz; cin >> sz; vector<int> b(sz); for (int i = 0; i < sz; i++) { cin >> b[i]; b[i] -= 1; busy[b[i]] = 1; } if (sz >= M) { vector<int> dp(n, -1e9); for (int i = 0; i < n; i++) { if (!busy[i]) dp[i] = 0; for (int j : g[i]) { if (dp[j] != -1e9) smax(dp[i], dp[j] + 1); } } if (dp[c] == -1e9) dp[c] = -1; cout << dp[c] << en; } else { int ans = -1e9; for (auto [i, j] : di[c]) { if (!busy[i]) smax(ans, j); } if (ans == -1e9) ans = -1; cout << ans << en; } for (int i : b) busy[i] = 0; } return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:29:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   29 |             for (auto [u, d] : di[j]) {
      |                       ^
bitaro.cpp:66:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   66 |             for (auto [i, j] : di[c]) {
      |                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...