제출 #1087911

#제출 시각아이디문제언어결과실행 시간메모리
10879114QT0RBitaro’s Party (JOI18_bitaro)C++17
0 / 100
7 ms8028 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<int,int> vector<pii> best[100003]; vector<int> graph[100003]; vector<int> rev[100003]; bool aval[100003]; int vis[100003]; int dp[100003]; const int siz=300; int dfs(int v){ dp[v]=0; int ans=1e9; for (auto u : rev[v]){ ans=min(ans,dfs(u)); dp[v]=max(dp[v],dp[u]+1); } return aval[v]?ans:min(dp[v],ans); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,m,q; cin >> n >> m >> q; for (int i = 1,s,t; i<=m; i++){ cin >> s >> t; graph[s].push_back(t); rev[t].push_back(s); } priority_queue<pii> pq; for (int i = 1; i<=n; i++){ pq.push({0,i}); for (auto u : rev[i]){ for (auto [v,d] : best[u]){ pq.push({d+1,v}); } } for (;best[i].size()<=siz && pq.size();pq.pop()){ auto [d,v] = pq.top(); if (vis[v]!=i){ vis[v]=i; best[i].push_back({v,d}); } } for(;pq.size();pq.pop()); } vector<int> wej; for (int i = 1,fin,num; i<=q; i++){ cin >> fin >> num; for (int j = 0,v; j<num; j++){ cin >> v; wej.push_back(v); } for (auto u : wej)aval[u]=true; if (num>=siz){ int wyn=dfs(fin); if (wyn==1e9)cout << "-1\n"; else cout << dp[fin]-wyn << '\n'; } else{ int ans=-1; for (auto [u,d] : best[fin]){ if (!aval[u])ans=max(ans,d); } cout << ans << '\n'; } for (auto u : wej)aval[u]=false; wej.clear(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...