#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
typedef long long ll;
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(dist[4][i]<=1)
good=1;
else
{
good=0;
if(dist[1][i]>=dist[1][s])
{
if(dist[2][i]+1>=dist[2][s])
good=1;
}
if(dist[2][i]>=dist[2][s])
{
if(dist[1][i]+1>=dist[1][s])
good=1;
}
if(dist[1][i]==dist[2][i]&&dist[1][i]+1>=dist[1][s]&&dist[2][i]+1>=dist[2][s])
good=1;
}
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 |
2 ms |
4948 KB |
Partially correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
5 |
Incorrect |
2 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 |
3 ms |
4948 KB |
Output isn't correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Incorrect |
2 ms |
5076 KB |
Output isn't correct |
13 |
Correct |
3 ms |
5076 KB |
Output is correct |
14 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Incorrect |
3 ms |
5072 KB |
Output isn't correct |
17 |
Incorrect |
3 ms |
5076 KB |
Output isn't correct |
18 |
Incorrect |
3 ms |
5076 KB |
Output isn't correct |
19 |
Correct |
3 ms |
5076 KB |
Output is correct |
20 |
Correct |
3 ms |
5076 KB |
Output is correct |
21 |
Correct |
3 ms |
5076 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 |
6960 KB |
Output is correct |
2 |
Incorrect |
25 ms |
7728 KB |
Output isn't correct |
3 |
Correct |
21 ms |
6996 KB |
Output is correct |
4 |
Incorrect |
26 ms |
7848 KB |
Output isn't correct |
5 |
Correct |
19 ms |
6856 KB |
Output is correct |
6 |
Correct |
20 ms |
7056 KB |
Output is correct |
7 |
Correct |
25 ms |
7292 KB |
Output is correct |
8 |
Correct |
24 ms |
7264 KB |
Output is correct |
9 |
Incorrect |
31 ms |
7764 KB |
Output isn't correct |
10 |
Correct |
118 ms |
12152 KB |
Output is correct |
11 |
Incorrect |
42 ms |
9244 KB |
Output isn't correct |
12 |
Correct |
63 ms |
10280 KB |
Output is correct |
13 |
Incorrect |
51 ms |
9500 KB |
Output isn't correct |
14 |
Correct |
40 ms |
8900 KB |
Output is correct |
15 |
Correct |
62 ms |
10444 KB |
Output is correct |
16 |
Correct |
66 ms |
10708 KB |
Output is correct |
17 |
Correct |
68 ms |
10064 KB |
Output is correct |
18 |
Incorrect |
58 ms |
10084 KB |
Output isn't correct |
19 |
Correct |
82 ms |
11312 KB |
Output is correct |
20 |
Incorrect |
158 ms |
14180 KB |
Output isn't correct |
21 |
Incorrect |
95 ms |
12480 KB |
Output isn't correct |
22 |
Correct |
80 ms |
11464 KB |
Output is correct |
23 |
Partially correct |
86 ms |
12440 KB |
Partially correct |
24 |
Correct |
85 ms |
12360 KB |
Output is correct |
25 |
Incorrect |
86 ms |
11980 KB |
Output isn't correct |
26 |
Partially correct |
76 ms |
11548 KB |
Partially correct |
27 |
Correct |
92 ms |
12508 KB |
Output is correct |
28 |
Correct |
109 ms |
12472 KB |
Output is correct |
29 |
Correct |
112 ms |
12904 KB |
Output is correct |
30 |
Incorrect |
166 ms |
14984 KB |
Output isn't correct |
31 |
Incorrect |
104 ms |
13644 KB |
Output isn't correct |
32 |
Correct |
97 ms |
12476 KB |
Output is correct |
33 |
Partially correct |
96 ms |
12744 KB |
Partially correct |
34 |
Incorrect |
109 ms |
13008 KB |
Output isn't correct |
35 |
Incorrect |
94 ms |
12768 KB |
Output isn't correct |
36 |
Incorrect |
89 ms |
13008 KB |
Output isn't correct |
37 |
Correct |
126 ms |
14236 KB |
Output is correct |
38 |
Correct |
116 ms |
13836 KB |
Output is correct |
39 |
Correct |
137 ms |
13908 KB |
Output is correct |
40 |
Incorrect |
169 ms |
15408 KB |
Output isn't correct |
41 |
Correct |
219 ms |
17656 KB |
Output is correct |