#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
5720 KB |
Output is correct |
2 |
Correct |
2 ms |
5720 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
2 ms |
5724 KB |
Output is correct |
5 |
Correct |
2 ms |
5724 KB |
Output is correct |
6 |
Correct |
2 ms |
5976 KB |
Output is correct |
7 |
Correct |
2 ms |
5720 KB |
Output is correct |
8 |
Correct |
2 ms |
5720 KB |
Output is correct |
9 |
Correct |
2 ms |
5720 KB |
Output is correct |
10 |
Correct |
2 ms |
5720 KB |
Output is correct |
11 |
Correct |
2 ms |
5976 KB |
Output is correct |
12 |
Correct |
2 ms |
5980 KB |
Output is correct |
13 |
Correct |
2 ms |
5980 KB |
Output is correct |
14 |
Correct |
2 ms |
5724 KB |
Output is correct |
15 |
Correct |
2 ms |
5728 KB |
Output is correct |
16 |
Correct |
2 ms |
5980 KB |
Output is correct |
17 |
Correct |
2 ms |
5724 KB |
Output is correct |
18 |
Correct |
2 ms |
5724 KB |
Output is correct |
19 |
Correct |
3 ms |
5720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
5720 KB |
Output is correct |
2 |
Correct |
2 ms |
5720 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
2 ms |
5724 KB |
Output is correct |
5 |
Correct |
2 ms |
5724 KB |
Output is correct |
6 |
Correct |
2 ms |
5976 KB |
Output is correct |
7 |
Correct |
2 ms |
5720 KB |
Output is correct |
8 |
Correct |
2 ms |
5720 KB |
Output is correct |
9 |
Correct |
2 ms |
5720 KB |
Output is correct |
10 |
Correct |
2 ms |
5720 KB |
Output is correct |
11 |
Correct |
2 ms |
5976 KB |
Output is correct |
12 |
Correct |
2 ms |
5980 KB |
Output is correct |
13 |
Correct |
2 ms |
5980 KB |
Output is correct |
14 |
Correct |
2 ms |
5724 KB |
Output is correct |
15 |
Correct |
2 ms |
5728 KB |
Output is correct |
16 |
Correct |
2 ms |
5980 KB |
Output is correct |
17 |
Correct |
2 ms |
5724 KB |
Output is correct |
18 |
Correct |
2 ms |
5724 KB |
Output is correct |
19 |
Correct |
3 ms |
5720 KB |
Output is correct |
20 |
Correct |
20 ms |
7088 KB |
Output is correct |
21 |
Correct |
20 ms |
7104 KB |
Output is correct |
22 |
Correct |
22 ms |
7016 KB |
Output is correct |
23 |
Correct |
20 ms |
7000 KB |
Output is correct |
24 |
Correct |
36 ms |
8924 KB |
Output is correct |
25 |
Correct |
36 ms |
8920 KB |
Output is correct |
26 |
Correct |
39 ms |
8920 KB |
Output is correct |
27 |
Correct |
39 ms |
9688 KB |
Output is correct |
28 |
Correct |
41 ms |
12160 KB |
Output is correct |
29 |
Correct |
39 ms |
12248 KB |
Output is correct |
30 |
Correct |
37 ms |
11980 KB |
Output is correct |
31 |
Correct |
34 ms |
12196 KB |
Output is correct |
32 |
Correct |
35 ms |
11992 KB |
Output is correct |
33 |
Correct |
32 ms |
11468 KB |
Output is correct |
34 |
Correct |
39 ms |
11576 KB |
Output is correct |
35 |
Correct |
33 ms |
11472 KB |
Output is correct |
36 |
Correct |
34 ms |
11732 KB |
Output is correct |
37 |
Correct |
34 ms |
11480 KB |
Output is correct |
38 |
Correct |
34 ms |
11616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
5720 KB |
Output is correct |
2 |
Correct |
2 ms |
5720 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
2 ms |
5724 KB |
Output is correct |
5 |
Correct |
2 ms |
5724 KB |
Output is correct |
6 |
Correct |
2 ms |
5976 KB |
Output is correct |
7 |
Correct |
2 ms |
5720 KB |
Output is correct |
8 |
Correct |
2 ms |
5720 KB |
Output is correct |
9 |
Correct |
2 ms |
5720 KB |
Output is correct |
10 |
Correct |
2 ms |
5720 KB |
Output is correct |
11 |
Correct |
2 ms |
5976 KB |
Output is correct |
12 |
Correct |
2 ms |
5980 KB |
Output is correct |
13 |
Correct |
2 ms |
5980 KB |
Output is correct |
14 |
Correct |
2 ms |
5724 KB |
Output is correct |
15 |
Correct |
2 ms |
5728 KB |
Output is correct |
16 |
Correct |
2 ms |
5980 KB |
Output is correct |
17 |
Correct |
2 ms |
5724 KB |
Output is correct |
18 |
Correct |
2 ms |
5724 KB |
Output is correct |
19 |
Correct |
3 ms |
5720 KB |
Output is correct |
20 |
Correct |
20 ms |
7088 KB |
Output is correct |
21 |
Correct |
20 ms |
7104 KB |
Output is correct |
22 |
Correct |
22 ms |
7016 KB |
Output is correct |
23 |
Correct |
20 ms |
7000 KB |
Output is correct |
24 |
Correct |
36 ms |
8924 KB |
Output is correct |
25 |
Correct |
36 ms |
8920 KB |
Output is correct |
26 |
Correct |
39 ms |
8920 KB |
Output is correct |
27 |
Correct |
39 ms |
9688 KB |
Output is correct |
28 |
Correct |
41 ms |
12160 KB |
Output is correct |
29 |
Correct |
39 ms |
12248 KB |
Output is correct |
30 |
Correct |
37 ms |
11980 KB |
Output is correct |
31 |
Correct |
34 ms |
12196 KB |
Output is correct |
32 |
Correct |
35 ms |
11992 KB |
Output is correct |
33 |
Correct |
32 ms |
11468 KB |
Output is correct |
34 |
Correct |
39 ms |
11576 KB |
Output is correct |
35 |
Correct |
33 ms |
11472 KB |
Output is correct |
36 |
Correct |
34 ms |
11732 KB |
Output is correct |
37 |
Correct |
34 ms |
11480 KB |
Output is correct |
38 |
Correct |
34 ms |
11616 KB |
Output is correct |
39 |
Incorrect |
32 ms |
11092 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |