#include <bits/stdc++.h>
using namespace std;
#define rep(i , j , k) for (int i = j; i < (int)k; i++)
#define pb push_back
#define mt make_tuple
#define for_all(x) x.begin(),x.end()
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef long double ld;
typedef complex<ld> point;
inline void fileIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
template<class T , class S>
inline bool smin(T &a, S b) { return (T)b < a ? a = b , 1 : 0; }
template<class T , class S>
inline bool smax(T &a, S b) { return a < (T)b ? a = b , 1 : 0; }
constexpr int N = 1e6 + 10;
constexpr int MOD = 1e9 + 7;
template<typename T>
inline T mod(T &v) { return v = (v % MOD + MOD) % MOD; }
template<typename S, typename T>
inline S add(S &l, T r) { return mod(l += r); }
ll po(ll v, ll u) { return u ? po(v * v % MOD , u >> 1) * (u & 1 ? v : 1) % MOD : 1; }
int n , m;
int s , t , a , b, dist[N];
vector<int> adj[N];
int L , R , Q[N];
void bfs(int so) {
memset(dist , -1, sizeof(dist));
dist[so] = 0;
L = 0, R = 1;
Q[0] = so;
while (L < R) {
int me = Q[L++];
for (auto e : adj[me])
if (!~dist[e]) {
dist[e] = dist[me] + 1;
Q[R++] = e;
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifndef LOCAL
// fileIO("forbidden1");
#endif
cin >> n >> m >> s >> t >> a >> b;
rep(i , 0 , m) {
int u , v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
bfs(s);
int A = dist[a];
int B = dist[b];
bfs(t);
int C = dist[a];
int D = dist[b];
int res = min(C - A , D - B);
if (res < 0) res = -1;
cout << res << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
27776 KB |
Output is correct |
2 |
Correct |
29 ms |
27752 KB |
Output is correct |
3 |
Correct |
28 ms |
27768 KB |
Output is correct |
4 |
Incorrect |
30 ms |
27776 KB |
Output isn't correct |
5 |
Incorrect |
28 ms |
27740 KB |
Output isn't correct |
6 |
Correct |
29 ms |
27740 KB |
Output is correct |
7 |
Correct |
31 ms |
27772 KB |
Output is correct |
8 |
Incorrect |
33 ms |
27784 KB |
Output isn't correct |
9 |
Correct |
27 ms |
27776 KB |
Output is correct |
10 |
Correct |
25 ms |
27776 KB |
Output is correct |
11 |
Correct |
24 ms |
27776 KB |
Output is correct |
12 |
Incorrect |
25 ms |
27756 KB |
Output isn't correct |
13 |
Correct |
25 ms |
27776 KB |
Output is correct |
14 |
Incorrect |
32 ms |
27776 KB |
Output isn't correct |
15 |
Correct |
27 ms |
27792 KB |
Output is correct |
16 |
Incorrect |
27 ms |
27748 KB |
Output isn't correct |
17 |
Incorrect |
28 ms |
27772 KB |
Output isn't correct |
18 |
Incorrect |
35 ms |
27768 KB |
Output isn't correct |
19 |
Correct |
26 ms |
27776 KB |
Output is correct |
20 |
Correct |
28 ms |
27740 KB |
Output is correct |
21 |
Correct |
28 ms |
27776 KB |
Output is correct |
22 |
Correct |
31 ms |
27768 KB |
Output is correct |
23 |
Correct |
25 ms |
27768 KB |
Output is correct |
24 |
Incorrect |
32 ms |
27820 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
29220 KB |
Output is correct |
2 |
Incorrect |
66 ms |
29944 KB |
Output isn't correct |
3 |
Correct |
57 ms |
29276 KB |
Output is correct |
4 |
Incorrect |
66 ms |
29904 KB |
Output isn't correct |
5 |
Correct |
46 ms |
29152 KB |
Output is correct |
6 |
Correct |
47 ms |
29280 KB |
Output is correct |
7 |
Correct |
58 ms |
29408 KB |
Output is correct |
8 |
Correct |
51 ms |
29432 KB |
Output is correct |
9 |
Incorrect |
69 ms |
29924 KB |
Output isn't correct |
10 |
Correct |
165 ms |
34284 KB |
Output is correct |
11 |
Incorrect |
100 ms |
30968 KB |
Output isn't correct |
12 |
Correct |
124 ms |
31720 KB |
Output is correct |
13 |
Incorrect |
99 ms |
31096 KB |
Output isn't correct |
14 |
Correct |
88 ms |
30588 KB |
Output is correct |
15 |
Correct |
104 ms |
31836 KB |
Output is correct |
16 |
Correct |
112 ms |
31992 KB |
Output is correct |
17 |
Correct |
98 ms |
31600 KB |
Output is correct |
18 |
Incorrect |
108 ms |
31580 KB |
Output isn't correct |
19 |
Correct |
170 ms |
32900 KB |
Output is correct |
20 |
Incorrect |
229 ms |
35540 KB |
Output isn't correct |
21 |
Incorrect |
136 ms |
33400 KB |
Output isn't correct |
22 |
Correct |
129 ms |
32776 KB |
Output is correct |
23 |
Correct |
128 ms |
33340 KB |
Output is correct |
24 |
Correct |
132 ms |
33252 KB |
Output is correct |
25 |
Incorrect |
134 ms |
33000 KB |
Output isn't correct |
26 |
Correct |
130 ms |
32632 KB |
Output is correct |
27 |
Correct |
153 ms |
33368 KB |
Output is correct |
28 |
Correct |
168 ms |
33460 KB |
Output is correct |
29 |
Correct |
187 ms |
34240 KB |
Output is correct |
30 |
Incorrect |
246 ms |
36152 KB |
Output isn't correct |
31 |
Incorrect |
143 ms |
34168 KB |
Output isn't correct |
32 |
Correct |
147 ms |
33272 KB |
Output is correct |
33 |
Correct |
183 ms |
33576 KB |
Output is correct |
34 |
Incorrect |
179 ms |
33832 KB |
Output isn't correct |
35 |
Incorrect |
151 ms |
33528 KB |
Output isn't correct |
36 |
Incorrect |
136 ms |
33812 KB |
Output isn't correct |
37 |
Correct |
160 ms |
34552 KB |
Output is correct |
38 |
Correct |
173 ms |
34380 KB |
Output is correct |
39 |
Correct |
178 ms |
34552 KB |
Output is correct |
40 |
Incorrect |
224 ms |
36088 KB |
Output isn't correct |
41 |
Correct |
319 ms |
38264 KB |
Output is correct |