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 ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,m,q;
cin>>n>>m>>q;
ll s[m],e[m];
vector<ll>up[n+5],down[n+5];
for(ll i=0;i<m;i++){
cin>>s[i]>>e[i];
up[s[i]].pb(e[i]);
down[e[i]].pb(s[i]);
}
vector<bool>vis(n+5,1);
for(ll i=0;i<q;i++){
ll t,y;
cin>>t>>y;
ll c[y];
for(ll j=0;j<y;j++){
cin>>c[j];
vis[c[j]]=false;
}
ll ans=-1;
vector<ll>dp(n+5,-1);
dp[t]=0;
for(ll j=t;j>=1;j--){
if(dp[j]>-1){
for(auto x:down[j]){
dp[x]=max(dp[x],dp[j]+1);
}
}
}
for(ll j=1;j<=n;j++){
if(dp[j]>-1&&vis[j]){
ans=max(ans,dp[j]);
}
}
for(ll j=0;j<y;j++){
vis[c[j]]=true;
}
cout<<ans<<"\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |