# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
30126 | 2017-07-22T07:33:10 Z | cdemirer | 007 (CEOI14_007) | C++14 | 429 ms | 18004 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> llp; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vii> vvii; #define mp(x, y) make_pair(x, y) #define pb(x) push_back(x) int N, M; int Z, D, SV1, SV2; vvi edges; int sv1dists[200000], sv2dists[200000]; bool vis1[200000] = {0}; bool vis2[200000] = {0}; void bfs(int *dists, bool *vis, int st) { queue<int> Q; queue<int> Qt; int d = 0; Q.push(st); while (!Q.empty()) { while (!Q.empty()) { int x = Q.front(); Q.pop(); if (vis[x]) continue; dists[x] = d; vis[x] = true; for (int i = 0; i < edges[x].size(); i++) { if (vis[edges[x][i]]) continue; Qt.push(edges[x][i]); } } while (!Qt.empty()) { int x = Qt.front(); Qt.pop(); Q.push(x); } d++; } } int moveit(int x) { int cnt = 0; while (true) { bool fnd = false; for (int i = 0; i < edges[x].size(); i++) { int v = edges[x][i]; if (sv1dists[v] == sv1dists[x]-1 && sv1dists[v] == sv2dists[v]) { fnd = true; x = v; break; } } if (!fnd) return cnt; else cnt++; } } int main(int argc, char **argv) { //freopen("input", "r", stdin); //freopen("output", "w", stdout); scanf("%d%d", &N, &M); scanf("%d%d%d%d", &Z, &D, &SV1, &SV2); Z--; D--; SV1--; SV2--; edges.resize(N); for (int i = 0; i < M; i++) { int a, b; scanf("%d%d", &a, &b); a--, b--; edges[a].pb(b); edges[b].pb(a); } bfs(sv1dists, vis1, SV1); bfs(sv2dists, vis2, SV2); int ans = -1; ans = max(ans, min(sv1dists[D] - sv1dists[Z], sv2dists[D] - sv2dists[Z])); if (ans != -1 && sv1dists[D] == sv2dists[D] && sv1dists[Z] == sv2dists[Z]) { int a = moveit(D); int b = moveit(Z); if (a > b + ans) ans--; } printf("%d\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 3976 KB | Output is correct |
2 | Correct | 0 ms | 3976 KB | Output is correct |
3 | Correct | 0 ms | 3976 KB | Output is correct |
4 | Correct | 0 ms | 3976 KB | Output is correct |
5 | Correct | 0 ms | 3976 KB | Output is correct |
6 | Correct | 0 ms | 3976 KB | Output is correct |
7 | Correct | 0 ms | 3976 KB | Output is correct |
8 | Correct | 0 ms | 3976 KB | Output is correct |
9 | Correct | 0 ms | 3976 KB | Output is correct |
10 | Correct | 0 ms | 3976 KB | Output is correct |
11 | Correct | 0 ms | 3976 KB | Output is correct |
12 | Correct | 0 ms | 3976 KB | Output is correct |
13 | Correct | 0 ms | 3976 KB | Output is correct |
14 | Correct | 0 ms | 3976 KB | Output is correct |
15 | Correct | 0 ms | 3976 KB | Output is correct |
16 | Correct | 0 ms | 3976 KB | Output is correct |
17 | Correct | 0 ms | 3976 KB | Output is correct |
18 | Correct | 0 ms | 3976 KB | Output is correct |
19 | Correct | 0 ms | 3976 KB | Output is correct |
20 | Correct | 0 ms | 3976 KB | Output is correct |
21 | Correct | 0 ms | 3976 KB | Output is correct |
22 | Correct | 0 ms | 3976 KB | Output is correct |
23 | Correct | 0 ms | 3976 KB | Output is correct |
24 | Correct | 0 ms | 4108 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 6252 KB | Output is correct |
2 | Correct | 39 ms | 7216 KB | Output is correct |
3 | Correct | 26 ms | 6304 KB | Output is correct |
4 | Correct | 53 ms | 7400 KB | Output is correct |
5 | Correct | 23 ms | 6072 KB | Output is correct |
6 | Correct | 26 ms | 6480 KB | Output is correct |
7 | Correct | 33 ms | 6712 KB | Output is correct |
8 | Correct | 33 ms | 6712 KB | Output is correct |
9 | Correct | 49 ms | 7132 KB | Output is correct |
10 | Correct | 223 ms | 11616 KB | Output is correct |
11 | Correct | 89 ms | 9004 KB | Output is correct |
12 | Correct | 103 ms | 10188 KB | Output is correct |
13 | Correct | 69 ms | 9296 KB | Output is correct |
14 | Correct | 53 ms | 8548 KB | Output is correct |
15 | Correct | 86 ms | 10388 KB | Output is correct |
16 | Correct | 79 ms | 10668 KB | Output is correct |
17 | Correct | 79 ms | 9968 KB | Output is correct |
18 | Correct | 83 ms | 9968 KB | Output is correct |
19 | Correct | 169 ms | 11200 KB | Output is correct |
20 | Correct | 296 ms | 14064 KB | Output is correct |
21 | Correct | 133 ms | 12764 KB | Output is correct |
22 | Correct | 123 ms | 11584 KB | Output is correct |
23 | Correct | 146 ms | 12704 KB | Output is correct |
24 | Correct | 126 ms | 12540 KB | Output is correct |
25 | Correct | 109 ms | 12076 KB | Output is correct |
26 | Correct | 126 ms | 11636 KB | Output is correct |
27 | Correct | 143 ms | 12748 KB | Output is correct |
28 | Correct | 143 ms | 12752 KB | Output is correct |
29 | Correct | 143 ms | 13056 KB | Output is correct |
30 | Correct | 333 ms | 14948 KB | Output is correct |
31 | Correct | 153 ms | 14112 KB | Output is correct |
32 | Correct | 129 ms | 12696 KB | Output is correct |
33 | Correct | 133 ms | 12976 KB | Output is correct |
34 | Correct | 159 ms | 13408 KB | Output is correct |
35 | Correct | 139 ms | 13008 KB | Output is correct |
36 | Correct | 139 ms | 13420 KB | Output is correct |
37 | Correct | 143 ms | 14612 KB | Output is correct |
38 | Correct | 123 ms | 14376 KB | Output is correct |
39 | Correct | 189 ms | 14380 KB | Output is correct |
40 | Correct | 266 ms | 15880 KB | Output is correct |
41 | Correct | 429 ms | 18004 KB | Output is correct |