제출 #366107

#제출 시각아이디문제언어결과실행 시간메모리
366107Jarif_RahmanBitaro’s Party (JOI18_bitaro)C++17
0 / 100
3 ms748 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; int sq; vector<int> w; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q; sq = sqrt(n+0.0); w.resize(n, -1); vector<vector<int>> v(n); for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; a--, b--; v[b].pb(a); } vector<vector<pair<int, int>>> dps(n); for(int i = 0; i < n; i++){ w[i] = 0; dps[i].pb({-1, i}); for(int x: v[i]){ for(auto [c, nd]: dps[x]){ if(w[nd] == -1) w[nd] = c+1, dps[i].pb({-1, nd}); else w[nd] = max(w[nd], c+1); } } for(auto &[c, nd]: dps[i]) c = w[nd], w[nd] = -1; int el = min(sq, (int)dps[i].size()); sort(dps[i].rbegin(), dps[i].rend()); dps[i].resize(el); } vector<bool> busy(n, 0); while(q--){ int tj, yj; cin >> tj >> yj; tj--; vector<int> cbs(yj); for(int &x: cbs) cin >> x, x--, busy[x] = 1; if(yj < sq){ int ans = busy[tj] ? -1 : 0; for(auto [c, nd]: dps[tj]) if(!busy[nd]) ans = max(ans, c); cout << ans << "\n"; for(int x: cbs) busy[x] = 0; continue; } vector<int> dp(n, -1); for(int i = 0; i < n; i++){ if(!busy[i]) dp[i] = max(dp[i], 0); for(int x: v[i]) dp[i] = max(dp[i], dp[x]+1); } cout << dp[tj] << "\n"; for(int x: cbs) busy[x] = 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...