# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
888043 | PM1 | Bitaro’s Party (JOI18_bitaro) | C++17 | 3 ms | 5468 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
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++){
int p[v[i].size()];
memset(p,0,sizeof p);
pair<int,int>num;
while(pre[i].size()<sq){
for(int j=0;j<v[i].size();j++){
int x=v[i][j];
if(p[j]>=pre[x].size() )continue;
while( p[j]<pre[x].size()&&mark[pre[x][p[j]].fr] )p[j]++;//cout<<j<<" "<<p[j]<<endl;
if(p[j]>=pre[x].size())continue;
if(pre[x][p[j]].sc+1>=num.sc){
num.sc=pre[x][p[j]].sc+1;
num.fr=pre[x][p[j]].fr;
}
}
if(num.fr==0)break;
mark[num.fr]=1;
pre[i].push_back(num);
num={0,0};
}
if(pre[i].size()<sq){
pre[i].push_back({i,0});
mark[i]=1;
}
for(auto j:pre[i]){
assert(mark[j.fr]);
mark[j.fr]=0;
}
}
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){
int dp[t+1];
for(int i=1;i<=t;i++){
dp[i]=0;
if(mark[i])continue;
for(auto j:v[i]){
if(!mark[j])dp[i]=max(dp[i],dp[j]+1);
}
}
if(dp[t]==0 && mark[t])dp[y]=-1;
cout<<dp[t]<<'\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;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |