제출 #888051

#제출 시각아이디문제언어결과실행 시간메모리
888051PM1Bitaro’s Party (JOI18_bitaro)C++17
0 / 100
3 ms5468 KiB
#include <bits/stdc++.h> using namespace std; #define fr first #define sc second const int mxn=1e5+5,sq=130; int n,m,q,mark[mxn]; vector<int>v[mxn]; vector<pair<int,int> >pre[mxn]; bool cmp(pair<int,int>x,pair<int,int>y){ return x.sc>y.sc; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m>>q; for(int i=1;i<=m;i++){ int x,y; cin>>x>>y; v[y].push_back(x); } for(int i=1;i<=n;i++){ for(auto j:v[i]){ for(auto w:pre[j]){ if(mark[w.fr]){ pre[i][mark[w.fr]-1].sc=min(w.sc,pre[i][mark[w.fr]-1].sc+1); } else{ pre[i].push_back({w.fr,w.sc+1}); mark[w.fr]=pre[i].size(); } } } if(pre[i].size()<sq){ pre[i].push_back({i,0}); mark[i]=1; } for(auto j:pre[i]){ mark[j.fr]=0; } sort(pre[i].begin(),pre[i].end(),cmp); if(pre[i].size()>sq) pre[i].resize(sq); } while(q--){ int t,y; cin>>t>>y; int a[y]; for(int i=0;i<y;i++){ cin>>a[i]; mark[a[i]]=1; } if(y>=sq){ assert(1); cout<<0<<'\n'; } else{ int d=0; for(auto i:pre[t]){ if(!mark[i.fr]){ d=1; cout<<i.sc<<'\n'; break; } } if(!d) cout<<-1<<'\n'; } for(int i=0;i<y;i++) mark[a[i]]=0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...