제출 #471580

#제출 시각아이디문제언어결과실행 시간메모리
471580RainbowbunnyBitaro’s Party (JOI18_bitaro)C++17
14 / 100
92 ms11468 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; const int SQRT = 0; int n, m, q; int dp[MAXN]; bool Mark[MAXN]; vector <int> Adj[MAXN]; vector <pair <int, int> > Dist[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> q; if(q > 1) { return 0; } for(int i = 1; i <= m; i++) { int u, v; cin >> u >> v; Adj[v].push_back(u); } for(int i = 1; i <= n; i++) { set <int> S; for(auto x : Adj[i]) { for(auto y : Dist[x]) { dp[y.second] = max(dp[y.second], y.first + 1); S.insert(y.second); } } S.insert(i); vector <pair <int, int> > tmp; for(auto x : S) { tmp.emplace_back(dp[x], x); dp[x] = 0; } sort(tmp.begin(), tmp.end()); while(tmp.empty() == false and Dist[i].size() < SQRT) { Dist[i].push_back(tmp.back()); tmp.pop_back(); } } while(q--) { int t, sz; cin >> t >> sz; vector <int> tmp(sz); for(auto &x : tmp) { cin >> x; Mark[x] = true; } bool ok = false; for(int i = 0; i < (int)Dist[t].size(); i++) { if(!Mark[Dist[t][i].second]) { ok = true; cout << Dist[t][i].first << '\n'; break; } } if(!ok) { int ans = -1; for(int i = 1; i <= n; i++) { dp[i] = -1e9; } dp[t] = 0; for(int i = t; i >= 1; i--) { for(auto x : Adj[i]) { dp[x] = max(dp[x], dp[i] + 1); } if(!Mark[i]) { ans = max(ans, dp[i]); } } cout << ans << '\n'; } for(auto x : tmp) { Mark[x] = false; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...