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>
#define endl "\n"
using namespace std;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n,m,qu,a,b,x,y,used[200005],br[200005];
vector<int>v[200005],c;
void bfs(int beg)
{
used[beg]=1;
int w,nb;
queue<int>q;
q.push(beg);
//cout<<beg<<endl;
while(!q.empty())
{
w=q.front();
q.pop();
if(br[w])br[w]--;
if(br[w])continue;
for(int i=0; i<(int)(v[w].size()); i++)
{
nb=v[w][i];
q.push(nb);
used[nb]=used[w]+1;
}
}
}
void bfs1(int beg)
{
used[beg]=1;
int w,nb;
queue<int>q;
q.push(beg);
while(!q.empty())
{
w=q.front();
q.pop();
for(int i=0; i<(int)(v[w].size()); i++)
{
nb=v[w][i];
br[nb]++;
if(!used[nb])
{
q.push(nb);
used[nb]=used[w]+1;
}
}
}
}
void read()
{
cin>>n>>m>>qu;
for(int i=1; i<=m; i++)
{
cin>>a>>b;
v[b].push_back(a);
}
cin>>x>>y;
for(int j=1; j<=y; j++)
{
int h;
cin>>h;
c.push_back(h);
}
bfs1(x);
memset(used,0,sizeof(used));
bfs(x);
int ma=-1,num=0;
for(int j=1; j<=n; j++)
{
//cout<<used[j]<<" "<<j<<endl;
if(num==(int)(c.size())||j!=c[num])ma=max(ma,used[j]-1);
else num++;
}
cout<<ma<<endl;
}
int main()
{
speed();
read();
return 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... |