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;
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 vert,idx,ans;
int used[100001],forb[100001];
void dfs(int i)
{
used[i]=1;
//cout<<i<<endl;
if(i==vert)
{
dp[i]=0;
if(!forb[i])
ans=max(ans,dp[i]);
return;
}
for(int j=0; j<v[i].size(); j++)
{
int nb=v[i][j];
dfs(nb);
if(dp[nb]!=-1)
dp[i]=max(dp[i],dp[nb]+1);
}
if(!forb[i])
ans=max(ans,dp[i]);
}
void solve()
{
for(int i=1; i<=q; i++)
{
for(int j=1; j<=n; j++)
dp[j]=-1,used[j]=forb[j]=0;
idx=i;
int k,b;
cin>>vert>>k;
for(int j=1; j<=k; j++)
{
cin>>b;
forb[b]=i;
}
ans=-1;
dfs(1);
cout<<ans<<'\n';
}
}
int main()
{
speed();
read();
solve();
return 0;
}
Compilation message (stderr)
bitaro.cpp: In function 'void dfs(int)':
bitaro.cpp:42:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int j=0; j<v[i].size(); j++)
| ~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |