#pragma GCC optimize "-O3"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int read() {
char c = getchar();
int res = 0;
while (c < '0' || c > '9') c = getchar();
while (48 <= c && c <= 57) {
res = res * 10 + c - '0';
c = getchar();
}
return res;
}
const int N = 2e5 + 1;
vector<int> g[N];
int n, m;
int X, S, A, B;
int d[N];
int bfs(int s) {
queue<int> q;
for(int i = 1 ; i <= n ; ++i)
d[i] = N;
d[s] = 0; q.push(s);
while(q.size()) {
int u = q.front(); q.pop();
for(int v : g[u])
if (d[v] > d[u] + 1) {
d[v] = d[u] + 1;
q.push(v);
}
}
if (d[X] > d[S]) {
puts("-1");
exit(0);
}
return d[S] - d[X];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen("SPY.inp","r",stdin);
//freopen("SPY.out","w",stdout);
n = read(); m = read();
X = read(); S = read();
A = read(); B = read();
while(m--) {
int x = read();
int y = read();
g[x].pb(y);
g[y].pb(x);
}
cout << min(bfs(A),bfs(B));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5116 KB |
Output is correct |
2 |
Correct |
7 ms |
5116 KB |
Output is correct |
3 |
Correct |
7 ms |
5264 KB |
Output is correct |
4 |
Incorrect |
7 ms |
5264 KB |
Output isn't correct |
5 |
Incorrect |
6 ms |
5264 KB |
Output isn't correct |
6 |
Correct |
6 ms |
5264 KB |
Output is correct |
7 |
Correct |
6 ms |
5368 KB |
Output is correct |
8 |
Incorrect |
6 ms |
5368 KB |
Output isn't correct |
9 |
Correct |
7 ms |
5368 KB |
Output is correct |
10 |
Correct |
6 ms |
5368 KB |
Output is correct |
11 |
Correct |
6 ms |
5368 KB |
Output is correct |
12 |
Incorrect |
7 ms |
5368 KB |
Output isn't correct |
13 |
Correct |
7 ms |
5368 KB |
Output is correct |
14 |
Incorrect |
6 ms |
5368 KB |
Output isn't correct |
15 |
Correct |
7 ms |
5368 KB |
Output is correct |
16 |
Incorrect |
6 ms |
5368 KB |
Output isn't correct |
17 |
Incorrect |
6 ms |
5368 KB |
Output isn't correct |
18 |
Incorrect |
7 ms |
5368 KB |
Output isn't correct |
19 |
Correct |
7 ms |
5368 KB |
Output is correct |
20 |
Correct |
7 ms |
5368 KB |
Output is correct |
21 |
Correct |
6 ms |
5368 KB |
Output is correct |
22 |
Correct |
6 ms |
5368 KB |
Output is correct |
23 |
Correct |
7 ms |
5372 KB |
Output is correct |
24 |
Incorrect |
7 ms |
5372 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
6780 KB |
Output is correct |
2 |
Incorrect |
30 ms |
7420 KB |
Output isn't correct |
3 |
Correct |
25 ms |
7420 KB |
Output is correct |
4 |
Incorrect |
28 ms |
7420 KB |
Output isn't correct |
5 |
Correct |
21 ms |
7420 KB |
Output is correct |
6 |
Correct |
23 ms |
7420 KB |
Output is correct |
7 |
Correct |
29 ms |
7420 KB |
Output is correct |
8 |
Correct |
23 ms |
7420 KB |
Output is correct |
9 |
Incorrect |
36 ms |
7420 KB |
Output isn't correct |
10 |
Correct |
118 ms |
11784 KB |
Output is correct |
11 |
Incorrect |
45 ms |
11784 KB |
Output isn't correct |
12 |
Correct |
57 ms |
11784 KB |
Output is correct |
13 |
Incorrect |
52 ms |
11784 KB |
Output isn't correct |
14 |
Correct |
34 ms |
11784 KB |
Output is correct |
15 |
Correct |
59 ms |
11784 KB |
Output is correct |
16 |
Correct |
95 ms |
11784 KB |
Output is correct |
17 |
Correct |
56 ms |
11784 KB |
Output is correct |
18 |
Incorrect |
51 ms |
11784 KB |
Output isn't correct |
19 |
Correct |
97 ms |
11784 KB |
Output is correct |
20 |
Incorrect |
175 ms |
13184 KB |
Output isn't correct |
21 |
Incorrect |
82 ms |
13184 KB |
Output isn't correct |
22 |
Correct |
67 ms |
13184 KB |
Output is correct |
23 |
Correct |
87 ms |
13184 KB |
Output is correct |
24 |
Correct |
100 ms |
13184 KB |
Output is correct |
25 |
Incorrect |
78 ms |
13184 KB |
Output isn't correct |
26 |
Correct |
66 ms |
13184 KB |
Output is correct |
27 |
Correct |
85 ms |
13184 KB |
Output is correct |
28 |
Correct |
89 ms |
13184 KB |
Output is correct |
29 |
Correct |
118 ms |
13184 KB |
Output is correct |
30 |
Incorrect |
191 ms |
13692 KB |
Output isn't correct |
31 |
Incorrect |
133 ms |
13692 KB |
Output isn't correct |
32 |
Correct |
93 ms |
13692 KB |
Output is correct |
33 |
Correct |
89 ms |
13692 KB |
Output is correct |
34 |
Incorrect |
123 ms |
13692 KB |
Output isn't correct |
35 |
Incorrect |
86 ms |
13692 KB |
Output isn't correct |
36 |
Incorrect |
98 ms |
13692 KB |
Output isn't correct |
37 |
Correct |
126 ms |
13692 KB |
Output is correct |
38 |
Correct |
113 ms |
13692 KB |
Output is correct |
39 |
Correct |
127 ms |
13692 KB |
Output is correct |
40 |
Incorrect |
162 ms |
13692 KB |
Output isn't correct |
41 |
Correct |
229 ms |
15884 KB |
Output is correct |