#include <bits/stdc++.h>
using namespace std;
int n,m,s,d,a,b;
vector<int> muchii[200005];
int dist[5][200005];
void bfs(int start,int index)
{
for(int i=1;i<=n;i++)
dist[index][i]=1e9;
dist[index][start]=0;
queue<int> coada;
coada.push(start);
while(!coada.empty())
{
int nod=coada.front();
coada.pop();
for(int i:muchii[nod])
if(dist[index][i]>dist[index][nod]+1)
{
dist[index][i]=dist[index][nod]+1;
coada.push(i);
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>s>>d>>a>>b;
for(int i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
muchii[x].push_back(y);
muchii[y].push_back(x);
}
bfs(a,1);
bfs(b,2);
bfs(d,3);
bfs(s,4);
int minim=1e9;
for(int i=1;i<=n;i++)
{
bool good;
if((max(dist[1][i],dist[2][i]+1)>=max(dist[1][s],dist[2][s]))||dist[4][i]<=1)
good=1;
else
good=0;
if(!good)
minim=min(minim,dist[3][i]-2);
}
cout<<max(-1,minim);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Partially correct |
3 ms |
4948 KB |
Partially correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Incorrect |
3 ms |
5076 KB |
Output isn't correct |
13 |
Correct |
4 ms |
5076 KB |
Output is correct |
14 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
15 |
Correct |
3 ms |
5056 KB |
Output is correct |
16 |
Incorrect |
3 ms |
5076 KB |
Output isn't correct |
17 |
Incorrect |
4 ms |
5076 KB |
Output isn't correct |
18 |
Incorrect |
3 ms |
5076 KB |
Output isn't correct |
19 |
Correct |
4 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
3 ms |
4972 KB |
Output is correct |
22 |
Correct |
3 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Incorrect |
3 ms |
5076 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
6868 KB |
Output is correct |
2 |
Incorrect |
28 ms |
7776 KB |
Output isn't correct |
3 |
Correct |
21 ms |
7076 KB |
Output is correct |
4 |
Incorrect |
28 ms |
7832 KB |
Output isn't correct |
5 |
Incorrect |
20 ms |
6784 KB |
Output isn't correct |
6 |
Incorrect |
24 ms |
7136 KB |
Output isn't correct |
7 |
Correct |
25 ms |
7372 KB |
Output is correct |
8 |
Correct |
26 ms |
7280 KB |
Output is correct |
9 |
Incorrect |
37 ms |
7764 KB |
Output isn't correct |
10 |
Correct |
120 ms |
12124 KB |
Output is correct |
11 |
Incorrect |
43 ms |
9216 KB |
Output isn't correct |
12 |
Correct |
67 ms |
10348 KB |
Output is correct |
13 |
Incorrect |
61 ms |
9588 KB |
Output isn't correct |
14 |
Correct |
46 ms |
8856 KB |
Output is correct |
15 |
Correct |
74 ms |
10544 KB |
Output is correct |
16 |
Incorrect |
76 ms |
10684 KB |
Output isn't correct |
17 |
Correct |
57 ms |
10164 KB |
Output is correct |
18 |
Incorrect |
69 ms |
10120 KB |
Output isn't correct |
19 |
Correct |
106 ms |
11320 KB |
Output is correct |
20 |
Incorrect |
160 ms |
14200 KB |
Output isn't correct |
21 |
Incorrect |
89 ms |
12556 KB |
Output isn't correct |
22 |
Correct |
79 ms |
11448 KB |
Output is correct |
23 |
Correct |
93 ms |
12364 KB |
Output is correct |
24 |
Correct |
88 ms |
12388 KB |
Output is correct |
25 |
Incorrect |
84 ms |
11908 KB |
Output isn't correct |
26 |
Correct |
87 ms |
11576 KB |
Output is correct |
27 |
Correct |
99 ms |
12556 KB |
Output is correct |
28 |
Correct |
127 ms |
12468 KB |
Output is correct |
29 |
Correct |
113 ms |
12968 KB |
Output is correct |
30 |
Incorrect |
167 ms |
14884 KB |
Output isn't correct |
31 |
Incorrect |
128 ms |
13684 KB |
Output isn't correct |
32 |
Correct |
90 ms |
12396 KB |
Output is correct |
33 |
Partially correct |
94 ms |
12644 KB |
Partially correct |
34 |
Incorrect |
112 ms |
13100 KB |
Output isn't correct |
35 |
Incorrect |
105 ms |
12748 KB |
Output isn't correct |
36 |
Incorrect |
97 ms |
13068 KB |
Output isn't correct |
37 |
Incorrect |
126 ms |
14048 KB |
Output isn't correct |
38 |
Correct |
130 ms |
13956 KB |
Output is correct |
39 |
Correct |
138 ms |
13976 KB |
Output is correct |
40 |
Incorrect |
172 ms |
15504 KB |
Output isn't correct |
41 |
Correct |
214 ms |
17484 KB |
Output is correct |