#include <bits/stdc++.h>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
typedef pair<int, int> ii;
const int N = 2e5 + 5;
int n, m, s, d, a, b, dist[N];
vector<int> g[N];
ii bfs(int st) {
memset(dist, 63, sizeof dist);
queue<int> q;
q.push(st);
dist[st] = 0;
while (!q.empty()) {
int u = q.front(); q.pop();
fa (v, g[u]) if (dist[u] + 1 < dist[v]) {
dist[v] = dist[u] + 1;
q.push(v);
}
}
return ii(dist[a], dist[b]);
}
signed main() {
#ifdef BLU
in("blu.inp");
#endif
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m >> s >> d >> a >> b;
s--, d--, a--, b--;
fw (i, 0, m) {
int u, v;
cin >> u >> v;
u--, v--;
g[u].pb(v), g[v].pb(u);
}
ii dists = bfs(s), distd = bfs(d);
int sa = dists.fi, sb = dists.se, da = distd.fi, db = distd.se;
int tmp1 = da - sa, tmp2 = db - sb;
int ans = min(tmp1, tmp2);
if (ans < 0) cout << "-1";
else cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5880 KB |
Output is correct |
2 |
Correct |
7 ms |
5884 KB |
Output is correct |
3 |
Correct |
6 ms |
5884 KB |
Output is correct |
4 |
Incorrect |
7 ms |
5924 KB |
Output isn't correct |
5 |
Incorrect |
7 ms |
5924 KB |
Output isn't correct |
6 |
Correct |
6 ms |
5968 KB |
Output is correct |
7 |
Correct |
8 ms |
5980 KB |
Output is correct |
8 |
Incorrect |
7 ms |
5996 KB |
Output isn't correct |
9 |
Correct |
7 ms |
6036 KB |
Output is correct |
10 |
Correct |
7 ms |
6044 KB |
Output is correct |
11 |
Correct |
7 ms |
6044 KB |
Output is correct |
12 |
Incorrect |
7 ms |
6044 KB |
Output isn't correct |
13 |
Correct |
7 ms |
6084 KB |
Output is correct |
14 |
Incorrect |
8 ms |
6084 KB |
Output isn't correct |
15 |
Correct |
7 ms |
6084 KB |
Output is correct |
16 |
Incorrect |
9 ms |
6084 KB |
Output isn't correct |
17 |
Incorrect |
8 ms |
6084 KB |
Output isn't correct |
18 |
Incorrect |
7 ms |
6084 KB |
Output isn't correct |
19 |
Correct |
9 ms |
6084 KB |
Output is correct |
20 |
Correct |
7 ms |
6224 KB |
Output is correct |
21 |
Correct |
8 ms |
6224 KB |
Output is correct |
22 |
Correct |
8 ms |
6224 KB |
Output is correct |
23 |
Correct |
7 ms |
6224 KB |
Output is correct |
24 |
Incorrect |
7 ms |
6224 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
7264 KB |
Output is correct |
2 |
Incorrect |
35 ms |
7904 KB |
Output isn't correct |
3 |
Correct |
29 ms |
7904 KB |
Output is correct |
4 |
Incorrect |
52 ms |
7904 KB |
Output isn't correct |
5 |
Correct |
29 ms |
7904 KB |
Output is correct |
6 |
Correct |
32 ms |
7904 KB |
Output is correct |
7 |
Correct |
31 ms |
7904 KB |
Output is correct |
8 |
Correct |
33 ms |
7904 KB |
Output is correct |
9 |
Incorrect |
51 ms |
8032 KB |
Output isn't correct |
10 |
Correct |
172 ms |
12256 KB |
Output is correct |
11 |
Incorrect |
53 ms |
12256 KB |
Output isn't correct |
12 |
Correct |
81 ms |
12256 KB |
Output is correct |
13 |
Incorrect |
68 ms |
12256 KB |
Output isn't correct |
14 |
Correct |
62 ms |
12256 KB |
Output is correct |
15 |
Correct |
70 ms |
12256 KB |
Output is correct |
16 |
Correct |
76 ms |
12256 KB |
Output is correct |
17 |
Correct |
68 ms |
12256 KB |
Output is correct |
18 |
Incorrect |
71 ms |
12256 KB |
Output isn't correct |
19 |
Correct |
116 ms |
12256 KB |
Output is correct |
20 |
Incorrect |
217 ms |
13536 KB |
Output isn't correct |
21 |
Incorrect |
98 ms |
13536 KB |
Output isn't correct |
22 |
Correct |
88 ms |
13536 KB |
Output is correct |
23 |
Correct |
104 ms |
13536 KB |
Output is correct |
24 |
Correct |
109 ms |
13536 KB |
Output is correct |
25 |
Incorrect |
101 ms |
13536 KB |
Output isn't correct |
26 |
Correct |
95 ms |
13536 KB |
Output is correct |
27 |
Correct |
108 ms |
13536 KB |
Output is correct |
28 |
Correct |
133 ms |
13536 KB |
Output is correct |
29 |
Correct |
154 ms |
13536 KB |
Output is correct |
30 |
Incorrect |
233 ms |
14048 KB |
Output isn't correct |
31 |
Incorrect |
115 ms |
14048 KB |
Output isn't correct |
32 |
Correct |
107 ms |
14048 KB |
Output is correct |
33 |
Correct |
120 ms |
14048 KB |
Output is correct |
34 |
Incorrect |
131 ms |
14048 KB |
Output isn't correct |
35 |
Incorrect |
105 ms |
14048 KB |
Output isn't correct |
36 |
Incorrect |
112 ms |
14048 KB |
Output isn't correct |
37 |
Correct |
118 ms |
14048 KB |
Output is correct |
38 |
Correct |
140 ms |
14048 KB |
Output is correct |
39 |
Correct |
166 ms |
14048 KB |
Output is correct |
40 |
Incorrect |
205 ms |
14048 KB |
Output isn't correct |
41 |
Correct |
320 ms |
15928 KB |
Output is correct |