# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
132330 | 2019-07-18T17:33:54 Z | bogdan10bos | 007 (CEOI14_007) | C++14 | 365 ms | 17784 KB |
/// 00:04 why? #include <bits/stdc++.h> using namespace std; const int NMAX = 2e5 + 5; int N, M, S, D, A, B; vector<int> edg[NMAX]; vector<int> BFS(int start) { vector<int> d(N + 1, 1 << 30); d[start] = 0; queue<int> q; q.push(start); while(!q.empty()) { int nod = q.front(); q.pop(); for(auto nxt: edg[nod]) if(d[nxt] > d[nod] + 1) { d[nxt] = d[nod] + 1; q.push(nxt); } } return d; } int main() { //freopen("1.in", "r", stdin); scanf("%d%d", &N, &M); scanf("%d%d%d%d", &S, &D, &A, &B); for(int i = 1; i <= M; i++) { int x, y; scanf("%d%d", &x, &y); edg[x].push_back(y); edg[y].push_back(x); } auto dS = BFS(S); auto dD = BFS(D); if(dD[A] + 1 <= dS[A] || dD[B] + 1 <= dS[B]) { printf("-1\n"); exit(0); } int timp = -1; if(dD[A] - dS[A] != dD[B] - dS[B]) timp = min(dD[A] - dS[A], dD[B] - dS[B]); else { auto dA = BFS(A); auto dB = BFS(B); int maxStepsS = 0; for(int i = 1; i <= N; i++) if(dA[i] == dB[i] && dA[i] + dS[i] == dS[A]) maxStepsS = max(maxStepsS, dS[i]); int maxStepsD = 0; for(int i = 1; i <= N; i++) if(dA[i] == dB[i] && dA[i] + dD[i] == dD[A]) maxStepsD = max(maxStepsD, dD[i]); timp = min(dD[A] - dS[A], dD[B] - dS[B]); maxStepsD -= (dD[A] - dS[A]); if(maxStepsS < maxStepsD) timp--; } printf("%d\n", timp); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4984 KB | Output is correct |
2 | Correct | 6 ms | 4984 KB | Output is correct |
3 | Correct | 6 ms | 4984 KB | Output is correct |
4 | Correct | 6 ms | 4984 KB | Output is correct |
5 | Correct | 6 ms | 4984 KB | Output is correct |
6 | Correct | 6 ms | 4984 KB | Output is correct |
7 | Correct | 6 ms | 4984 KB | Output is correct |
8 | Correct | 6 ms | 4984 KB | Output is correct |
9 | Correct | 6 ms | 4984 KB | Output is correct |
10 | Correct | 6 ms | 4984 KB | Output is correct |
11 | Correct | 6 ms | 4984 KB | Output is correct |
12 | Correct | 6 ms | 4984 KB | Output is correct |
13 | Correct | 6 ms | 5112 KB | Output is correct |
14 | Correct | 6 ms | 4984 KB | Output is correct |
15 | Correct | 6 ms | 4984 KB | Output is correct |
16 | Correct | 6 ms | 5112 KB | Output is correct |
17 | Correct | 6 ms | 5112 KB | Output is correct |
18 | Correct | 6 ms | 5112 KB | Output is correct |
19 | Correct | 6 ms | 5112 KB | Output is correct |
20 | Correct | 6 ms | 4984 KB | Output is correct |
21 | Correct | 6 ms | 5112 KB | Output is correct |
22 | Correct | 7 ms | 4984 KB | Output is correct |
23 | Correct | 6 ms | 4984 KB | Output is correct |
24 | Correct | 6 ms | 4988 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 37 ms | 6904 KB | Output is correct |
2 | Correct | 53 ms | 7780 KB | Output is correct |
3 | Correct | 38 ms | 7036 KB | Output is correct |
4 | Correct | 50 ms | 7932 KB | Output is correct |
5 | Correct | 31 ms | 6520 KB | Output is correct |
6 | Correct | 33 ms | 6776 KB | Output is correct |
7 | Correct | 42 ms | 7288 KB | Output is correct |
8 | Correct | 43 ms | 7416 KB | Output is correct |
9 | Correct | 58 ms | 7772 KB | Output is correct |
10 | Correct | 192 ms | 12340 KB | Output is correct |
11 | Correct | 78 ms | 9336 KB | Output is correct |
12 | Correct | 105 ms | 10488 KB | Output is correct |
13 | Correct | 87 ms | 9596 KB | Output is correct |
14 | Correct | 59 ms | 8312 KB | Output is correct |
15 | Correct | 112 ms | 10472 KB | Output is correct |
16 | Correct | 96 ms | 9848 KB | Output is correct |
17 | Correct | 105 ms | 10104 KB | Output is correct |
18 | Correct | 123 ms | 10232 KB | Output is correct |
19 | Correct | 145 ms | 11512 KB | Output is correct |
20 | Correct | 256 ms | 14200 KB | Output is correct |
21 | Correct | 165 ms | 12644 KB | Output is correct |
22 | Correct | 175 ms | 11640 KB | Output is correct |
23 | Correct | 180 ms | 12408 KB | Output is correct |
24 | Correct | 185 ms | 12536 KB | Output is correct |
25 | Correct | 215 ms | 12108 KB | Output is correct |
26 | Correct | 143 ms | 11656 KB | Output is correct |
27 | Correct | 188 ms | 12540 KB | Output is correct |
28 | Correct | 201 ms | 12536 KB | Output is correct |
29 | Correct | 193 ms | 13108 KB | Output is correct |
30 | Correct | 267 ms | 14968 KB | Output is correct |
31 | Correct | 183 ms | 13688 KB | Output is correct |
32 | Correct | 183 ms | 12536 KB | Output is correct |
33 | Correct | 188 ms | 12792 KB | Output is correct |
34 | Correct | 202 ms | 13052 KB | Output is correct |
35 | Correct | 177 ms | 12792 KB | Output is correct |
36 | Correct | 167 ms | 13176 KB | Output is correct |
37 | Correct | 165 ms | 12652 KB | Output is correct |
38 | Correct | 225 ms | 14072 KB | Output is correct |
39 | Correct | 236 ms | 13944 KB | Output is correct |
40 | Correct | 249 ms | 15480 KB | Output is correct |
41 | Correct | 365 ms | 17784 KB | Output is correct |