# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
227440 | MKopchev | Bitaro’s Party (JOI18_bitaro) | C++14 | 1708 ms | 120184 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 nmax=1e5+42,CUT=100;
vector<int> adj[nmax],bck[nmax];
int n,m,q;
int sz,where;
int blocked[nmax];
bool is_blocked[nmax];
int dp[nmax];
int slow()
{
for(int i=1;i<=n;i++)
dp[i]=-1e9;
dp[where]=0;
for(int i=where-1;i>=1;i--)
{
for(auto k:adj[i])
dp[i]=max(dp[i],dp[k]+1);
}
int mx=-1;
for(int i=where;i>=1;i--)
if(is_blocked[i]==0)mx=max(mx,dp[i]);
return mx;
}
vector< pair<int/*distance*/,int/*start*/> > best[nmax];
int main()
{
scanf("%i%i%i",&n,&m,&q);
for(int i=1;i<=m;i++)
{
int u,v;
scanf("%i%i",&u,&v);
adj[u].push_back(v);
bck[v].push_back(u);
}
vector< pair<int/*distance*/,int/*start*/> > help={};
for(int i=1;i<=n;i++)
{
help={};
for(auto node_back:bck[i])
for(auto k:best[node_back])
help.push_back({k.first+1,k.second});
help.push_back({0,i});
sort(help.begin(),help.end());
reverse(help.begin(),help.end());
for(auto k:help)
{
if(is_blocked[k.second]==0)
{
is_blocked[k.second]=1;
best[i].push_back(k);
if(best[i].size()==CUT)break;
}
}
for(auto k:best[i])
is_blocked[k.second]=0;
}
for(int i=1;i<=q;i++)
{
scanf("%i%i",&where,&sz);
for(int j=1;j<=sz;j++)
{
scanf("%i",&blocked[j]);
is_blocked[blocked[j]]=1;
}
if(sz>=CUT)printf("%i\n",slow());
else
{
int mx=-1;
for(auto k:best[where])
if(is_blocked[k.second]==0)mx=max(mx,k.first);
printf("%i\n",mx);
}
for(int j=1;j<=sz;j++)
{
is_blocked[blocked[j]]=0;
}
}
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... |