# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
845984 | guagua0407 | Bitaro’s Party (JOI18_bitaro) | C++17 | 1103 ms | 117188 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.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int K=70;
const int mxn=1e5+5;
vector<int> adj[mxn];
vector<pair<int,int> > S[mxn];
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
auto st=clock();
int n,m,q;
cin>>n>>m>>q;
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
a--;
b--;
adj[b].push_back(a);
}
vector<int> mx(n,-1);
vector<vector<int>> rev(n);
for(int i=0;i<n;i++){
vector<int> use;
use.push_back(i);
mx[i]=0;
for(auto v:adj[i]){
for(auto u:S[v]){
if(mx[u.s]==-1){
use.push_back(u.s);
}
mx[u.s]=max(mx[u.s],u.f+1);
}
}
int mxx=0;
for(auto v:use){
rev[mx[v]].push_back(v);
mxx=max(mxx,mx[v]);
}
while((int)S[i].size()<K and mxx>=0){
while(mxx>=0 and rev[mxx].empty()) mxx--;
if(mxx>=0 and !rev[mxx].empty()){
S[i].push_back({mxx,rev[mxx].back()});
rev[mxx].pop_back();
}
}
for(auto v:use){
rev[mx[v]].clear();
mx[v]=-1;
}
}
vector<int> ok(n,1);
for(int i=0;i<q;i++){
int v;
cin>>v;
v--;
int t;
cin>>t;
vector<int> vec(t);
for(int j=0;j<t;j++){
cin>>vec[j];
vec[j]--;
ok[vec[j]]=0;
}
//sort(all(vec));
if(t>=(int)S[v].size()){
vector<int> d(n,-1);
d[v]=0;
for(int j=v;j>=0;j--){
if(d[j]==-1) continue;
for(auto u:adj[j]){
d[u]=max(d[u],d[j]+1);
}
}
int ans=-1;
for(int j=0;j<=v;j++){
if(ok[j]){
ans=max(ans,d[j]);
}
}
cout<<ans<<'\n';
}
else{
bool tf=false;
for(auto u:S[v]){
if(ok[u.s]){
cout<<u.f<<'\n';
tf=true;
break;
}
}
assert(tf);
}
for(int j=0;j<t;j++){
ok[vec[j]]=1;
}
}
}
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... |