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<iostream>
#include<vector>
#include<queue>
using namespace::std;
vector<int> v[100005];
int ar[100005],maxn,dp[100005];
int DFS(int i){
// cout<<i<<'\n';
for(auto a:v[i])
if(dp[a]==0 && (!ar[a] || v[a].size())){
DFS(a);
dp[i]=max(dp[i],(!ar[a] || dp[a]!=0)+dp[a]);
}
else if((!ar[a] || v[a].size())){
dp[i]=max(dp[i],1+dp[a]);
}
// cout<<i<<' '<<dp[i]<<'\n';
return dp[i];
}
int main(){
ios_base::sync_with_stdio(0);
int n,m,q;
cin>>n>>m>>q;
for(int i=0,l,r;i<m;i++)
cin>>l>>r,v[r].push_back(l);
while(q--){
int x,k;
maxn=0;
cin>>x>>k;
for(int i=0,t;i<k;i++)
cin>>t,ar[t]=1;
cout<<DFS(x)<<'\n';
for(int i=1;i<=n;i++)
ar[i]=0,dp[i]=0;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |