//#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[MAXN];
vi adj[MAXN];
pii bfs(int src, int x, int y, int p = 0) {
deque<int> pq;
mem(dp, 0x3f);
dp[src] = 0;
dp[p] = 0;
pq.pb(src);
while (!pq.empty()) {
int u = pq.front(); pq.pop_front();
for (int v: adj[u]) {
if (dp[v] != 1061109567)
continue;
dp[v] = dp[u] + 1;
pq.pb(v);
}
}
return mp(dp[x], dp[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);
pii a2 = bfs(d, a, b);
//cerr << a1.fi << "/" << a2.fi << " | " << a1.se << "/" << a2.se << "\n";
int ans = min(a2.fi - a1.fi, a2.se - a1.se);
if (a1.fi == a1.se) {
pii a3 = bfs(d, a, b, s);
if (a2 == a3)
ans--;
}
if (ans < 0) ans = -1;
pri(ans);
return 0;
}
Compilation message
007.cpp: In function 'int main()':
007.cpp:60: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:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &u, &v);
~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
27768 KB |
Output is correct |
2 |
Correct |
27 ms |
27768 KB |
Output is correct |
3 |
Partially correct |
28 ms |
27768 KB |
Partially correct |
4 |
Correct |
27 ms |
27768 KB |
Output is correct |
5 |
Correct |
28 ms |
27768 KB |
Output is correct |
6 |
Correct |
27 ms |
27768 KB |
Output is correct |
7 |
Partially correct |
27 ms |
27640 KB |
Partially correct |
8 |
Correct |
27 ms |
27768 KB |
Output is correct |
9 |
Partially correct |
27 ms |
27768 KB |
Partially correct |
10 |
Correct |
28 ms |
27768 KB |
Output is correct |
11 |
Partially correct |
27 ms |
27768 KB |
Partially correct |
12 |
Correct |
28 ms |
27768 KB |
Output is correct |
13 |
Partially correct |
28 ms |
27768 KB |
Partially correct |
14 |
Correct |
27 ms |
27768 KB |
Output is correct |
15 |
Partially correct |
27 ms |
27768 KB |
Partially correct |
16 |
Correct |
27 ms |
27768 KB |
Output is correct |
17 |
Correct |
27 ms |
27768 KB |
Output is correct |
18 |
Correct |
27 ms |
27768 KB |
Output is correct |
19 |
Partially correct |
28 ms |
27768 KB |
Partially correct |
20 |
Partially correct |
28 ms |
27768 KB |
Partially correct |
21 |
Correct |
27 ms |
27768 KB |
Output is correct |
22 |
Partially correct |
28 ms |
27896 KB |
Partially correct |
23 |
Correct |
28 ms |
27896 KB |
Output is correct |
24 |
Correct |
28 ms |
27844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
58 ms |
29048 KB |
Partially correct |
2 |
Correct |
68 ms |
29688 KB |
Output is correct |
3 |
Partially correct |
57 ms |
29304 KB |
Partially correct |
4 |
Correct |
73 ms |
29816 KB |
Output is correct |
5 |
Correct |
53 ms |
29080 KB |
Output is correct |
6 |
Correct |
56 ms |
29304 KB |
Output is correct |
7 |
Partially correct |
61 ms |
29432 KB |
Partially correct |
8 |
Partially correct |
63 ms |
29304 KB |
Partially correct |
9 |
Correct |
74 ms |
29816 KB |
Output is correct |
10 |
Partially correct |
206 ms |
34040 KB |
Partially correct |
11 |
Correct |
98 ms |
30712 KB |
Output is correct |
12 |
Partially correct |
144 ms |
31364 KB |
Partially correct |
13 |
Correct |
102 ms |
30968 KB |
Output is correct |
14 |
Correct |
122 ms |
30456 KB |
Output is correct |
15 |
Partially correct |
126 ms |
31484 KB |
Partially correct |
16 |
Correct |
151 ms |
31572 KB |
Output is correct |
17 |
Partially correct |
121 ms |
31300 KB |
Partially correct |
18 |
Correct |
126 ms |
31096 KB |
Output is correct |
19 |
Partially correct |
161 ms |
32248 KB |
Partially correct |
20 |
Correct |
255 ms |
35064 KB |
Output is correct |
21 |
Correct |
157 ms |
32732 KB |
Output is correct |
22 |
Partially correct |
150 ms |
32064 KB |
Partially correct |
23 |
Correct |
144 ms |
32632 KB |
Output is correct |
24 |
Partially correct |
164 ms |
32704 KB |
Partially correct |
25 |
Correct |
157 ms |
32320 KB |
Output is correct |
26 |
Correct |
134 ms |
32056 KB |
Output is correct |
27 |
Partially correct |
189 ms |
32744 KB |
Partially correct |
28 |
Partially correct |
194 ms |
32680 KB |
Partially correct |
29 |
Partially correct |
187 ms |
33528 KB |
Partially correct |
30 |
Correct |
275 ms |
35600 KB |
Output is correct |
31 |
Correct |
226 ms |
33452 KB |
Output is correct |
32 |
Partially correct |
160 ms |
32696 KB |
Partially correct |
33 |
Correct |
154 ms |
32880 KB |
Output is correct |
34 |
Correct |
181 ms |
33144 KB |
Output is correct |
35 |
Correct |
175 ms |
32860 KB |
Output is correct |
36 |
Correct |
181 ms |
33144 KB |
Output is correct |
37 |
Correct |
183 ms |
33784 KB |
Output is correct |
38 |
Partially correct |
221 ms |
33684 KB |
Partially correct |
39 |
Partially correct |
232 ms |
33656 KB |
Partially correct |
40 |
Correct |
259 ms |
35436 KB |
Output is correct |
41 |
Partially correct |
370 ms |
37660 KB |
Partially correct |