제출 #59464

#제출 시각아이디문제언어결과실행 시간메모리
59464tmwilliamlin168Bitaro’s Party (JOI18_bitaro)C++14
14 / 100
2083 ms23232 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<int, int> #define fi first #define se second inline int in() { int result = 0; char ch = getchar_unlocked(); while(true) { if(ch >= '0' && ch <= '9') break; ch = getchar_unlocked(); } result = ch-'0'; while(true) { ch = getchar_unlocked(); if (ch < '0' || ch > '9') break; result = result*10 + (ch - '0'); } return result; } inline void out(int x) { if(!x) { putchar_unlocked('0'); return; } if(x<0) { putchar_unlocked('-'); x=-x; } int rev=x, c=0; while(!(rev%10)) { ++c; rev/=10; } rev=0; while(x) { rev=rev*10+x%10; x/=10; } while(rev) { putchar_unlocked(rev%10+'0'); rev/=10; } while(c--) putchar_unlocked('0'); } const int mxN=1e5, bs=10; int n, m, q, dp2[mxN], c[mxN]; vector<int> adj[mxN]; vector<pii> dp1[mxN]; priority_queue<pii, vector<pii>, greater<pii>> pq; bool a[mxN]; int main() { n=in(), m=in(), q=in(); while(m--) { int u=in()-1, v=in()-1; adj[v].push_back(u); } for(int i=0; i<n; ++i) { pq.push({0, i}); for(int v : adj[i]) { for(pii p : dp1[v]) { pq.push({p.fi+1, p.se}); if(pq.size()>bs) pq.pop(); } } while(!pq.empty()) { dp1[i].push_back(pq.top()); pq.pop(); } } while(q--) { int t=in()-1, y=in(), ans=-1; for(int i=0; i<y; ++i) { c[i]=in()-1; a[c[i]]=1; } if(y>bs) { memset(dp2, -1, 4*(t+1)); for(int i=0; i<=t; ++i) { dp2[i]=a[i]?-n:0; for(int v : adj[i]) dp2[i]=max(dp2[v]+1, dp2[i]); } ans=max(dp2[t], ans); } else { for(int i=dp1[t].size()-1; i>=0; --i) { if(a[dp1[t][i].se]) continue; ans=dp1[t][i].fi; break; } } for(int i=0; i<y; ++i) a[c[i]]=0; out(ans); putchar_unlocked('\n'); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...