# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
454820 | 2021-08-05T08:34:35 Z | kingfran1907 | 007 (CEOI14_007) | C++14 | 370 ms | 17720 KB |
#include <bits/stdc++.h> #define X first #define Y second using namespace std; typedef long long llint; const int maxn = 2e5+10; const int base = 31337; const int mod = 1e9+7; const int inf = 0x3f3f3f3f; const int logo = 18; const int off = 1 << logo; const int treesiz = off << 1; int n, m; int s, d, a, b; vector< int > graph[maxn]; int disa[maxn], disb[maxn]; int dp[maxn]; void calc(int x, int dis[maxn]) { for (int i = 1; i <= n; i++) dis[i] = -1; queue< int > q; dis[x] = 0; q.push(x); while (!q.empty()) { int x = q.front(); q.pop(); for (int tren : graph[x]) { if (dis[tren] == -1) { dis[tren] = dis[x] + 1; q.push(tren); } } } } bool cmp(int a, int b) { return disa[a] < disa[b]; } int main() { scanf("%d%d", &n, &m); scanf("%d%d%d%d", &s, &d, &a, &b); for (int i = 0; i < m; i++) { int x, y; scanf("%d%d", &x, &y); graph[x].push_back(y); graph[y].push_back(x); } calc(a, disa); calc(b, disb); int ax = disa[d] - disa[s]; int bx = disb[d] - disb[s]; if (ax > bx) swap(ax, bx); if (ax < 0 || bx < 0) printf("-1\n"); else if (ax + 1 == bx) printf("%d\n", ax); else { vector< int > v; for (int i = 1; i <= n; i++) v.push_back(i); sort(v.begin(), v.end(), cmp); for (int i : v) { dp[i] = 0; for (int tren : graph[i]) { if (disa[i] > disa[tren] && disb[i] > disb[tren]) dp[i] = max(dp[i], 1 + dp[tren]); } } int ps = dp[s]; int pd = dp[d]; if (ps + ax < pd) printf("%d\n", ax - 1); else printf("%d\n", ax); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4940 KB | Output is correct |
2 | Correct | 3 ms | 4940 KB | Output is correct |
3 | Correct | 3 ms | 4940 KB | Output is correct |
4 | Correct | 3 ms | 4940 KB | Output is correct |
5 | Correct | 3 ms | 4940 KB | Output is correct |
6 | Correct | 3 ms | 4940 KB | Output is correct |
7 | Correct | 3 ms | 4940 KB | Output is correct |
8 | Correct | 3 ms | 4940 KB | Output is correct |
9 | Correct | 3 ms | 4940 KB | Output is correct |
10 | Correct | 3 ms | 4940 KB | Output is correct |
11 | Correct | 3 ms | 5068 KB | Output is correct |
12 | Correct | 3 ms | 4940 KB | Output is correct |
13 | Correct | 3 ms | 4940 KB | Output is correct |
14 | Correct | 3 ms | 4940 KB | Output is correct |
15 | Correct | 3 ms | 4940 KB | Output is correct |
16 | Correct | 3 ms | 4940 KB | Output is correct |
17 | Correct | 3 ms | 4940 KB | Output is correct |
18 | Correct | 3 ms | 4940 KB | Output is correct |
19 | Correct | 3 ms | 4940 KB | Output is correct |
20 | Correct | 3 ms | 4940 KB | Output is correct |
21 | Partially correct | 3 ms | 5044 KB | Partially correct |
22 | Correct | 3 ms | 4940 KB | Output is correct |
23 | Correct | 4 ms | 4940 KB | Output is correct |
24 | Correct | 4 ms | 4940 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 7012 KB | Output is correct |
2 | Correct | 37 ms | 7808 KB | Output is correct |
3 | Correct | 27 ms | 7160 KB | Output is correct |
4 | Correct | 38 ms | 7904 KB | Output is correct |
5 | Partially correct | 27 ms | 7012 KB | Partially correct |
6 | Partially correct | 29 ms | 7108 KB | Partially correct |
7 | Correct | 31 ms | 7332 KB | Output is correct |
8 | Correct | 34 ms | 7424 KB | Output is correct |
9 | Correct | 45 ms | 7816 KB | Output is correct |
10 | Correct | 176 ms | 12224 KB | Output is correct |
11 | Correct | 65 ms | 9348 KB | Output is correct |
12 | Correct | 87 ms | 10320 KB | Output is correct |
13 | Correct | 81 ms | 9688 KB | Output is correct |
14 | Correct | 43 ms | 8184 KB | Output is correct |
15 | Correct | 82 ms | 10488 KB | Output is correct |
16 | Partially correct | 91 ms | 10800 KB | Partially correct |
17 | Correct | 79 ms | 10232 KB | Output is correct |
18 | Correct | 92 ms | 10304 KB | Output is correct |
19 | Correct | 118 ms | 11364 KB | Output is correct |
20 | Correct | 204 ms | 14260 KB | Output is correct |
21 | Correct | 120 ms | 12600 KB | Output is correct |
22 | Correct | 110 ms | 11532 KB | Output is correct |
23 | Correct | 131 ms | 12484 KB | Output is correct |
24 | Correct | 127 ms | 12412 KB | Output is correct |
25 | Correct | 130 ms | 12088 KB | Output is correct |
26 | Correct | 109 ms | 11728 KB | Output is correct |
27 | Correct | 131 ms | 12540 KB | Output is correct |
28 | Correct | 127 ms | 12648 KB | Output is correct |
29 | Correct | 193 ms | 13112 KB | Output is correct |
30 | Correct | 243 ms | 14944 KB | Output is correct |
31 | Correct | 142 ms | 13676 KB | Output is correct |
32 | Correct | 134 ms | 12512 KB | Output is correct |
33 | Correct | 131 ms | 12812 KB | Output is correct |
34 | Correct | 158 ms | 13072 KB | Output is correct |
35 | Correct | 131 ms | 12852 KB | Output is correct |
36 | Correct | 133 ms | 13076 KB | Output is correct |
37 | Partially correct | 168 ms | 14276 KB | Partially correct |
38 | Correct | 150 ms | 13964 KB | Output is correct |
39 | Correct | 169 ms | 14056 KB | Output is correct |
40 | Correct | 227 ms | 15556 KB | Output is correct |
41 | Correct | 370 ms | 17720 KB | Output is correct |