//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
int n, m, dp[2][MAXN];
vi adj[MAXN];
pii bfs(int src, int x, int y, int p) {
deque<int> pq;
mem(dp[p], 0x3f);
dp[p][src] = 0;
pq.pb(src);
while (!pq.empty()) {
int u = pq.front(); pq.pop_front();
for (int v: adj[u]) {
if (dp[p][v] != 1061109567)
continue;
dp[p][v] = dp[p][u] + 1;
pq.pb(v);
}
}
return mp(dp[p][x], dp[p][y]);
}
int main() {
int s, d, a, b;
scanf("%d %d %d %d %d %d", &n, &m, &s, &d, &a, &b);
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d %d", &u, &v);
adj[u].pb(v);
adj[v].pb(u);
}
pii a1 = bfs(s, a, b, 0);
pii a2 = bfs(d, a, b, 1);
pii a3 = bfs(a, a, b, 0);
pii a4 = bfs(b, a, b, 1);
cerr << a1.fi << "/" << a2.fi << " | " << a1.se << "/" << a2.se << "\n";
int ans = min(a2.fi - a1.fi, a2.se - a1.se);
if (a2.fi == a2.se) {
return -1;
for (int i = 1; i <= n; i++) {
}
}
if (ans < 0) ans = -1;
pri(ans);
return 0;
}
Compilation message
007.cpp: In function 'int main()':
007.cpp:68:6: warning: variable 'a3' set but not used [-Wunused-but-set-variable]
pii a3 = bfs(a, a, b, 0);
^~
007.cpp:69:6: warning: variable 'a4' set but not used [-Wunused-but-set-variable]
pii a4 = bfs(b, a, b, 1);
^~
007.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d %d %d", &n, &m, &s, &d, &a, &b);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &u, &v);
~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
2 |
Incorrect |
31 ms |
31608 KB |
Expected integer, but "8/10" found |
3 |
Runtime error |
29 ms |
31608 KB |
Execution failed because the return code was nonzero |
4 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
5 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
6 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
7 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
8 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
9 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
10 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
11 |
Incorrect |
31 ms |
31608 KB |
Expected integer, but "31/33" found |
12 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
13 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
14 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
15 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
16 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
17 |
Runtime error |
31 ms |
31736 KB |
Execution failed because the return code was nonzero |
18 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
19 |
Runtime error |
31 ms |
31692 KB |
Execution failed because the return code was nonzero |
20 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
21 |
Incorrect |
31 ms |
31608 KB |
Expected integer, but "31/36" found |
22 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
23 |
Runtime error |
31 ms |
31608 KB |
Execution failed because the return code was nonzero |
24 |
Runtime error |
31 ms |
31736 KB |
Execution failed because the return code was nonzero |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
63 ms |
32892 KB |
Execution failed because the return code was nonzero |
2 |
Runtime error |
76 ms |
33456 KB |
Execution failed because the return code was nonzero |
3 |
Runtime error |
66 ms |
32904 KB |
Execution failed because the return code was nonzero |
4 |
Runtime error |
78 ms |
33528 KB |
Execution failed because the return code was nonzero |
5 |
Incorrect |
60 ms |
32888 KB |
Expected integer, but "126/173" found |
6 |
Incorrect |
74 ms |
33168 KB |
Expected integer, but "5013/5191" found |
7 |
Runtime error |
113 ms |
33232 KB |
Execution failed because the return code was nonzero |
8 |
Runtime error |
81 ms |
33144 KB |
Execution failed because the return code was nonzero |
9 |
Runtime error |
106 ms |
33528 KB |
Execution failed because the return code was nonzero |
10 |
Runtime error |
219 ms |
37752 KB |
Execution failed because the return code was nonzero |
11 |
Runtime error |
117 ms |
34424 KB |
Execution failed because the return code was nonzero |
12 |
Runtime error |
126 ms |
35192 KB |
Execution failed because the return code was nonzero |
13 |
Runtime error |
127 ms |
34672 KB |
Execution failed because the return code was nonzero |
14 |
Runtime error |
110 ms |
34240 KB |
Execution failed because the return code was nonzero |
15 |
Runtime error |
206 ms |
35192 KB |
Execution failed because the return code was nonzero |
16 |
Incorrect |
174 ms |
35576 KB |
Expected integer, but "1312/1721" found |
17 |
Runtime error |
150 ms |
35092 KB |
Execution failed because the return code was nonzero |
18 |
Runtime error |
151 ms |
35164 KB |
Execution failed because the return code was nonzero |
19 |
Runtime error |
230 ms |
36216 KB |
Execution failed because the return code was nonzero |
20 |
Runtime error |
320 ms |
39032 KB |
Execution failed because the return code was nonzero |
21 |
Runtime error |
226 ms |
36596 KB |
Execution failed because the return code was nonzero |
22 |
Runtime error |
192 ms |
35960 KB |
Execution failed because the return code was nonzero |
23 |
Incorrect |
211 ms |
36600 KB |
Expected integer, but "11011/15191" found |
24 |
Runtime error |
207 ms |
36588 KB |
Execution failed because the return code was nonzero |
25 |
Runtime error |
197 ms |
36232 KB |
Execution failed because the return code was nonzero |
26 |
Incorrect |
246 ms |
36104 KB |
Expected integer, but "1210/2510" found |
27 |
Runtime error |
220 ms |
36600 KB |
Execution failed because the return code was nonzero |
28 |
Runtime error |
232 ms |
36768 KB |
Execution failed because the return code was nonzero |
29 |
Runtime error |
222 ms |
37496 KB |
Execution failed because the return code was nonzero |
30 |
Runtime error |
310 ms |
39544 KB |
Execution failed because the return code was nonzero |
31 |
Runtime error |
233 ms |
37468 KB |
Execution failed because the return code was nonzero |
32 |
Runtime error |
197 ms |
36600 KB |
Execution failed because the return code was nonzero |
33 |
Incorrect |
208 ms |
36844 KB |
Expected integer, but "1602/2720" found |
34 |
Runtime error |
226 ms |
37008 KB |
Execution failed because the return code was nonzero |
35 |
Runtime error |
201 ms |
36820 KB |
Execution failed because the return code was nonzero |
36 |
Runtime error |
182 ms |
36984 KB |
Execution failed because the return code was nonzero |
37 |
Incorrect |
224 ms |
37724 KB |
Expected integer, but "1582/3612" found |
38 |
Runtime error |
259 ms |
37700 KB |
Execution failed because the return code was nonzero |
39 |
Runtime error |
264 ms |
37624 KB |
Execution failed because the return code was nonzero |
40 |
Runtime error |
373 ms |
39288 KB |
Execution failed because the return code was nonzero |
41 |
Runtime error |
403 ms |
41464 KB |
Execution failed because the return code was nonzero |