제출 #930512

#제출 시각아이디문제언어결과실행 시간메모리
930512iskhakkutbilimBitaro’s Party (JOI18_bitaro)C++17
0 / 100
5 ms8028 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define all(a) a.begin(), a.end() const int N = 1e5; const int SZ = 400; vector<int> g[N+5], gg[N+5]; vector<pair<int,int> > calc[N+1]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, q; cin >> n >> m >> q; for(int i = 0;i < m; i++){ int a, b; cin >> a >> b; g[a].push_back(b); gg[b].push_back(a); } vector<int> reach, dist(n+1), last(n+1, 0); for(int i = 1;i <= n; i++){ reach.push_back(i); for(auto to : gg[i]){ for(auto [d, u] : calc[to]){ if(last[u] == i){ dist[u] = max(dist[u], d + 1); }else{ dist[u] = d + 1; last[u] = i; reach.push_back(u); } } } sort(all(reach),[&](int a, int b){ return dist[a] > dist[b]; }); for(int j = 0;j < min(SZ, (int)reach.size()); j++){ calc[i].push_back({dist[reach[j]], reach[j]}); } reach.clear(); } int timer = 1; vector<int> del(n+1, 0); while(q--){ int v, k; cin >> v >> k; for(int i = 0;i < k; i++){ int x; cin >> x; del[x] = timer; } if(k < SZ){ int ans = -1; for(auto [d, u] : calc[v]){ if(del[u] != timer){ ans = d; break; } } cout << ans << '\n'; }else{ vector<int> d(n+1, -1); for(int i = 1;i <= n; i++){ if(del[i] != timer) del[i] = max(del[i], 0); for(int to : g[i]){ del[to] = max(del[to], del[i] + 1); } } cout << del[v] << '\n'; } timer++; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...