Submission #920794

#TimeUsernameProblemLanguageResultExecution timeMemory
920794adaawfBitaro’s Party (JOI18_bitaro)C++14
100 / 100
1756 ms482796 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cstring> using namespace std; vector<pair<int, int>> a[100005]; vector<int> g[100005]; int h = 400, dd[100005], b[100005], f[100005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, q; cin >> n >> m >> q; a[1].push_back({0, 1}); for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; g[v].push_back(u); } memset(b, -1, sizeof b); for (int i = 1; i <= n; i++) { a[i].push_back({0, i}); vector<int> v; for (int w : g[i]) { for (auto x : a[w]) { if (b[x.second] == -1) v.push_back(x.second); if (b[x.second] < x.first + 1) { b[x.second] = x.first + 1; } } } for (int w : v) { a[i].push_back({b[w], w}); b[w] = -1; } sort(a[i].begin(), a[i].end(), greater<pair<int, int>>()); while (a[i].size() > h) a[i].pop_back(); } for (int jj = 0; jj < q; jj++) { int x, y; cin >> x >> y; vector<int> v; for (int i = 0; i < y; i++) { int z; cin >> z; dd[z] = 1; v.push_back(z); } if (y < h) { int flag = 0; for (auto w : a[x]) { if (dd[w.second] == 0) { cout << w.first; flag = 1; break; } } if (flag == 0) cout << -1; } else { for (int i = 1; i <= x; i++) { if (dd[i] == 1) { f[i] = -1e9; } else f[i] = 0; } for (int i = 1; i <= x; i++) { for (int w : g[i]) { f[i] = max(f[i], f[w] + 1); } } if (f[x] < 0) cout << -1; else cout << f[x]; } cout << '\n'; for (int w : v) dd[w] = 0; } }

Compilation message (stderr)

bitaro.cpp: In function 'int main()':
bitaro.cpp:37:28: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |         while (a[i].size() > h) a[i].pop_back();
      |                ~~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...