# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
991932 | simona1230 | Bitaro’s Party (JOI18_bitaro) | C++17 | 762 ms | 524288 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;
const int s=-1;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n,m,q;
vector<int> v[100001];
void read()
{
cin>>n>>m>>q;
for(int i=1; i<=m; i++)
{
int x,y;
cin>>x>>y;
v[x].push_back(y);
}
}
int dp[100001];
int f[100001];
deque <pair<int,int> > p[100001];
deque<pair<int,int> > merge_(deque<pair<int,int> > d1,deque<pair<int,int> > d2,int add)// d2+1
{
deque<pair<int,int> > d;
int i=d1.size()-1;
int j=d2.size()-1;
while(d.size()<s&&(i>=0||j>=0))
{
//cout<<i<<" "<<j<<endl;
if(j==-1||i!=-1&&d1[i].second>d2[j].second+add)
{
d.push_front(d1[i]);
i--;
}
else
{
//cout<<"- "<<endl;
d.push_front({d2[j].first,d2[j].second+add});
j--;
}
//cout<<i<<" "<<j<<endl;
}
//cout<<"out"<<endl;
return d;
}
void prec()
{
for(int i=1;i<=n;i++)
{
p[i]=merge_(p[i],{{i,0}},0);
for(int j=0;j<v[i].size();j++)
{
int nb=v[i][j];
p[nb]=merge_(p[nb],p[i],1);
}
/*cout<<i<<" ";
for(int j=0;j<p[i].size();j++)
cout<<p[i][j].first<<", "<<p[i][j].second<<endl;*/
}
}
void solve()
{
for(int i=1; i<=q; i++)
{
int t,k;
cin>>t>>k;
for(int j=1; j<=k; j++)
{
int x;
cin>>x;
f[x]=i;
}
if(k>s)
{
for(int j=1; j<=n; j++)
dp[j]=-1;
for(int j=1; j<=n; j++)
{
if(f[j]!=i)dp[j]=max(dp[j],0);
for(int x=0; x<v[j].size(); x++)
if(dp[j]!=-1)dp[v[j][x]]=max(dp[v[j][x]],dp[j]+1);
}
cout<<dp[t]<<endl;
}
else
{
int ans=-1;
for(int j=0; j<p[t].size(); j++)
{
if(f[p[t][j].first]!=i)
ans=max(ans,p[t][j].second);
}
cout<<ans<<endl;
}
}
}
int main()
{
speed();
read();
prec();
solve();
return 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... |