제출 #820062

#제출 시각아이디문제언어결과실행 시간메모리
820062smirichtoBitaro’s Party (JOI18_bitaro)C++17
0 / 100
2067 ms8324 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] ; vector<pi> merge(vector<pi>& a , const vector<pi>& b) { vector<pi> tmp ; for(auto p : b) a.pb({p.F+1 , p.S}) ; sort(all(a)) ; reverse(all(a)) ; map<int,int> vis ; for(auto p : a){ if(vis[p.S]) continue; vis[p.S] = 1 ; tmp.pb(p) ; if(tmp.size()>B+3) break ; } return tmp ; } map<int,int> marked ; int ans ; void work(int t , int dep) { if(!marked[t]) ckmax(ans , dep) ; for(int to : adj[t]) work(to , dep+1) ; } 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 ; marked.clear() ; for(int i = 1 ; i<=y ; i++){ int x ; cin>>x ; marked[x] = 1 ; } ans = -1 ; if(y<=B){ for(auto & i : best[t]){ if(!marked[i.S]){ ans = i.F ; break ; } } } else{ work(t , 0) ; } cout<<ans<<endl; } } 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...