제출 #989117

#제출 시각아이디문제언어결과실행 시간메모리
989117aykhnBitaro’s Party (JOI18_bitaro)C++17
100 / 100
1277 ms437768 KiB
#include <bits/stdc++.h> using namespace std; const int MXN = 2e5 + 5; const int B = 500; int n, m, q; vector<int> adj[MXN]; int used[MXN], dp[MXN], inq[MXN], in[MXN]; vector<array<int, 2>> b[MXN]; vector<int> o; void init(int a) { used[a] = 1; b[a].push_back({0, a}); vector<array<int, 2>> nw; for (int v : adj[a]) { if (!used[v]) init(v); nw.clear(); int i = 0, j = 0; while (nw.size() < B + 1 && i < b[a].size() && j < b[v].size()) { if (in[b[a][i][1]]) { i++; continue; } if (in[b[v][j][1]]) { j++; continue; } if (b[a][i][0] > b[v][j][0] + 1) nw.push_back(b[a][i]), in[b[a][i++][1]] = 1; else nw.push_back({b[v][j][0] + 1, b[v][j][1]}), in[b[v][j++][1]] = 1; } while (nw.size() < B + 1 && i < b[a].size()) if (in[b[a][i][1]] && ++i) continue; else nw.push_back(b[a][i]), in[b[a][i++][1]] = 1; while (nw.size() < B + 1 && j < b[v].size()) if (in[b[v][j][1]] && ++j) continue; else nw.push_back({b[v][j][0] + 1, b[v][j][1]}), in[b[v][j++][1]] = 1; swap(nw, b[a]); for (array<int, 2> &i : b[a]) in[i[1]] = 0; } } void dfs(int a) { used[a] = 1; for (int v : adj[a]) { if (used[v]) continue; dfs(v); } o.push_back(a); } void _() { cin >> n >> m >> q; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; adj[v].push_back(u); } for (int i = n; i >= 1; i--) { if (!used[i]) init(i); } while (q--) { int t, sz; cin >> t >> sz; vector<int> v(sz); for (int &i : v) cin >> i, inq[i] = 1; if (sz > B) { o.clear(); for (int i = 1; i <= n; i++) used[i] = 0, dp[i] = 0; dfs(t); reverse(o.begin(), o.end()); int res = -1; for (int i : o) { if (!inq[i]) res = max(res, dp[i]); for (int j : adj[i]) dp[j] = max(dp[j], dp[i] + 1); } cout << res << '\n'; } else { int res = -1; for (array<int, 2> &i : b[t]) { if (!inq[i[1]]) { res = i[0]; break; } } cout << res << '\n'; } for (int &i : v) inq[i] = 0; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; for (int tt = 1; tt <= t; tt++) { _(); } }

컴파일 시 표준 에러 (stderr) 메시지

bitaro.cpp: In function 'void init(int)':
bitaro.cpp:24:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         while (nw.size() < B + 1 && i < b[a].size() && j < b[v].size())
      |                                     ~~^~~~~~~~~~~~~
bitaro.cpp:24:58: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         while (nw.size() < B + 1 && i < b[a].size() && j < b[v].size())
      |                                                        ~~^~~~~~~~~~~~~
bitaro.cpp:39:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         while (nw.size() < B + 1 && i < b[a].size()) if (in[b[a][i][1]] && ++i) continue; else nw.push_back(b[a][i]), in[b[a][i++][1]] = 1;
      |                                     ~~^~~~~~~~~~~~~
bitaro.cpp:40:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         while (nw.size() < B + 1 && j < b[v].size()) if (in[b[v][j][1]] && ++j) continue; else nw.push_back({b[v][j][0] + 1, b[v][j][1]}), in[b[v][j++][1]] = 1;
      |                                     ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...