Submission #967345

#TimeUsernameProblemLanguageResultExecution timeMemory
967345pccBitaro’s Party (JOI18_bitaro)C++17
100 / 100
1931 ms215120 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx2,popcnt,sse4") #pragma GCC optimize("O3,unroll-loops") #define ll long long #define pll pair<ll,ll> #define pii pair<int,int> #define fs first #define sc second #define tlll tuple<ll,ll,ll> const int B = 180; const int mxn = 1e5+10; vector<int> paths[mxn]; int N,M,Q; namespace SMALL{ vector<pii> dp[mxn]; bitset<mxn> done; void trim(int now){ vector<int> all; vector<pii> v; sort(dp[now].rbegin(),dp[now].rend()); for(auto &i:dp[now]){ if(v.size()>=B)break; if(done[i.sc])continue; v.push_back(i); all.push_back(i.sc); done[i.sc] = true; } for(auto &i:all)done[i] = false; dp[now].swap(v); return; } void PREC(){ for(int i = 1;i<=N;i++)dp[i].push_back(pii(0,i)); for(int i = 1;i<=N;i++){ for(auto nxt:paths[i]){ for(auto &j:dp[i])dp[nxt].push_back(pii(j.fs+1,j.sc)); trim(nxt); } } return; } void GETANS(int tar,vector<int> ban){ for(auto &i:ban)done[i] = true; int ans = -1; for(auto &j:dp[tar]){ if(done[j.sc])continue; ans = j.fs; break; } for(auto &i:ban)done[i] = false; cout<<ans<<'\n'; return; return; } } namespace BIG{ int dist[mxn]; void GETANS(int tar,vector<int> ban){ memset(dist,0,sizeof(dist)); for(auto &i:ban)dist[i] = -mxn*2; for(int i = 1;i<=N;i++){ for(auto nxt:paths[i]){ dist[nxt] = max(dist[nxt],dist[i]+1); } } cout<<(dist[tar]<0?-1:dist[tar])<<'\n'; return; } } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N>>M>>Q; for(int i = 0;i<M;i++){ int a,b; cin>>a>>b; paths[a].push_back(b); } SMALL::PREC(); while(Q--){ int st; cin>>st; vector<int> v; int k; cin>>k; while(k--){ int tmp; cin>>tmp; v.push_back(tmp); } if(v.size()+10<B)SMALL::GETANS(st,v); else BIG::GETANS(st,v); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...