제출 #1028592

#제출 시각아이디문제언어결과실행 시간메모리
1028592ngraceBitaro’s Party (JOI18_bitaro)C++14
0 / 100
1 ms2652 KiB
#include <bits/stdc++.h> using namespace std; #define v vector #define ii pair<int,int> #define fi first #define se second const int SIZ = 200; v<v<int>> adj(100000); int main(){ cin.tie(NULL); ios_base::sync_with_stdio(false); int N,M,Q; cin>>N>>M>>Q; for(int i=0; i<M; i++){ int s,e; cin>>s>>e; s--; e--; adj[e].push_back(s); } v<v<ii>> longest(N); v<int> used(N,-1); v<int> dists(N); for(int i=0; i<N; i++){ for(int c:adj[i]){ for(auto it:longest[c]){ if(used[it.se]!=i) dists[it.se]=0; used[it.se]=i; dists[it.se] = max(dists[i], it.fi+1); } } longest[i].push_back({0, i}); for(int c:adj[i]){ for(auto it:longest[c]){ if(used[it.se]==i){ used[it.se]=-1; longest[i].push_back({dists[it.se], it.se}); } } } sort(longest[i].rbegin(), longest[i].rend()); while(longest[i].size()>SIZ+1) longest[i].pop_back(); } v<int> Y(N,-1); for(int q=0; q<Q; q++){ int t,y; cin>>t>>y; t--; for(int i=0; i<y; i++){ int c; cin>>c; c--; Y[c] = q; } if(y<SIZ && false){ bool done=false; for(ii it:longest[t]){ if(Y[it.se]!=q){ cout<<it.fi<<endl; done=true; break; } } if(!done) cout<<-1<<endl; } else{ v<int> dp(N,-1); dp[t] = -1; for(int i=t; i>=0; i--){ if(dp[i]==-1) continue; for(int c:adj[t]) dp[c] = max(dp[c], dp[i]+1); } int out=-1; for(int i=0; i<=t; i++) if(Y[i]!=q) out = max(out, dp[i]); cout<<out<<endl; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...