Submission #820092

#TimeUsernameProblemLanguageResultExecution timeMemory
820092smirichtoBitaro’s Party (JOI18_bitaro)C++17
0 / 100
4 ms5460 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back #define pi pair<int,int> #define F first #define S second #define all(x) (x).begin(), (x).end() #define alll(x) ((x).begin()+1), (x).end() #define clean(v) (v).resize(distance((v).begin(), unique(all(v)))); #define yes cout<<"Yes"<<endl; #define no cout<<"No"<<endl; #define mod mod #define endl '\n' mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll mod = 998244353; void io() { ios::sync_with_stdio(false); cin.tie(NULL); } template<class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } template<class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } void nop() { cout << -1 << endl; return; } const int N = 1e5+5 , B = 350 ; vector<int> adj[N] ; vector<pi> best[N] ; int vis[N] ; vector<pi> merge(const vector<pi>& a , const vector<pi>& b) { vector<pi> tmp ; int sa = a.size() , sb = b.size() ; int i = 0 , j = 0 ; while(tmp.size()<B+3 && i<sa && j<sb){ if(a[i].F>=b[j].F+1){ tmp.pb(a[i]) ; vis[a[i].S] = 1 ; i++ ; } else{ tmp.pb(make_pair(b[j].F +1 , b[j].S)) ; vis[b[j].S] = 1 ; j++ ; } while(i<sa && vis[a[i].S]) i++ ; while(j<sb && vis[b[j].S]) j++ ; } while(tmp.size()<B+3 && j<sb){ tmp.pb(make_pair(b[j].F +1 , b[j].S)) ; j++ ; } while(tmp.size()<B+3 && i<sa){ tmp.pb(a[i]) ; i++ ; } for(auto p : tmp) vis[p.S] = 0 ; return tmp ; } int marked[N] ; int ans ; void solve() { int n , m , q ; cin>>n>>m>>q ; for(int i = 1 ; i<=m ; i++){ int u , v ; cin>>u>>v ; adj[v].pb(u) ; } for(int i = 1 ; i<=n ; i++){ best[i].pb({0 , i}) ; for(int to : adj[i]){ best[i] = merge(best[i] , best[to]) ; } } while(q--){ int t , y ; cin>>t>>y ; vector<int> v ; for(int i = 1 ; i<=y ; i++){ int x ; cin>>x ; marked[x] = 1 ; v.pb(x) ; } ans = -1 ; if(y<=B){ for(auto & i : best[t]){ if(!marked[i.S]){ ans = i.F ; break ; } } } else{ queue<pi> q ; q.push({t , 0}) ; vector<int> done(n+1 , 0) ; while(!q.empty()){ auto p = q.front() ; q.pop() ; if(done[p.F]) continue; done[p.F] = 1 ; if(!marked[p.F]) ckmax(ans , p.S) ; for(int to : adj[p.F]){ q.push({to , p.S + 1}) ; } } } cout<<ans<<endl; for(int j : v) marked[j] = 0 ; } } int main() { io(); ll tt = 1; //cin>>tt ; while (tt--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...