# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
92920 | 2019-01-05T16:34:42 Z | Flying_dragon_02 | 007 (CEOI14_007) | C++14 | 353 ms | 24684 KB |
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair typedef pair<int, int> ii; const int N = 2e5 + 5; int n, m, s, d, a, b, dista[N], distb[N], dist[N]; vector<int> graph[N]; queue<int> q; int get(int f) { int res = 0; for(int i = 1; i <= N - 5; i++) dist[i] = N; dist[f] = 0; q.push(f); while(!q.empty()) { int u = q.front(); q.pop(); res = max(res, dist[u]); for(int i = 0; i < graph[u].size(); i++) { int v = graph[u][i]; if(dist[v] > dist[u] + 1 && dista[v] + 1 == dista[u] && distb[v] + 1 == distb[u]) { dist[v] = dist[u] + 1; q.push(v); } } } return res; } int main() { scanf("%d%d", &n, &m); scanf("%d%d%d%d", &s, &d, &a, &b); for(int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); graph[u].pb(v); graph[v].pb(u); } for(int i = 1; i <= N - 5; i++) { dista[i] = N; distb[i] = N; } dista[a] = 0; q.push(a); while(!q.empty()) { int u = q.front(); q.pop(); for(int i = 0; i < graph[u].size(); i++) { int v = graph[u][i]; if(dista[v] > dista[u] + 1) { dista[v] = dista[u] + 1; q.push(v); } } } distb[b] = 0; q.push(b); while(!q.empty()) { int u = q.front(); q.pop(); for(int i = 0; i < graph[u].size(); i++) { int v = graph[u][i]; if(distb[v] > distb[u] + 1) { distb[v] = distb[u] + 1; q.push(v); } } } int w1 = dista[d] - dista[s], w2 = distb[d] - distb[s]; if(min(w1, w2) < 0) { printf("-1"); exit(0); } int ans; if(w1 != w2) printf("%d", min(w1, w2)); else { int lmaoa = get(s), lmaob = get(d); if(lmaoa + w1 >= lmaob) ans = w1; else ans = w1 - 1; } if(ans < 0) printf("-1"); else printf("%d", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 6776 KB | Expected integer, but "00" found |
2 | Correct | 7 ms | 7416 KB | Output is correct |
3 | Correct | 8 ms | 7416 KB | Output is correct |
4 | Correct | 8 ms | 7288 KB | Output is correct |
5 | Correct | 8 ms | 7416 KB | Output is correct |
6 | Correct | 8 ms | 7416 KB | Output is correct |
7 | Correct | 8 ms | 7416 KB | Output is correct |
8 | Correct | 8 ms | 7416 KB | Output is correct |
9 | Correct | 8 ms | 7416 KB | Output is correct |
10 | Incorrect | 6 ms | 6520 KB | Output isn't correct |
11 | Incorrect | 7 ms | 6648 KB | Output isn't correct |
12 | Correct | 8 ms | 7416 KB | Output is correct |
13 | Correct | 8 ms | 7416 KB | Output is correct |
14 | Correct | 8 ms | 7416 KB | Output is correct |
15 | Correct | 7 ms | 7416 KB | Output is correct |
16 | Correct | 8 ms | 7416 KB | Output is correct |
17 | Correct | 7 ms | 7416 KB | Output is correct |
18 | Correct | 7 ms | 7416 KB | Output is correct |
19 | Correct | 9 ms | 7416 KB | Output is correct |
20 | Correct | 8 ms | 7416 KB | Output is correct |
21 | Incorrect | 7 ms | 6648 KB | Output isn't correct |
22 | Correct | 8 ms | 7416 KB | Output is correct |
23 | Correct | 8 ms | 7416 KB | Output is correct |
24 | Correct | 8 ms | 7416 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 9208 KB | Output is correct |
2 | Correct | 37 ms | 9976 KB | Output is correct |
3 | Correct | 29 ms | 9180 KB | Output is correct |
4 | Correct | 39 ms | 9976 KB | Output is correct |
5 | Incorrect | 28 ms | 8312 KB | Output isn't correct |
6 | Incorrect | 25 ms | 8568 KB | Output isn't correct |
7 | Correct | 29 ms | 9592 KB | Output is correct |
8 | Correct | 30 ms | 9592 KB | Output is correct |
9 | Correct | 45 ms | 10360 KB | Output is correct |
10 | Correct | 156 ms | 18680 KB | Output is correct |
11 | Correct | 53 ms | 11256 KB | Output is correct |
12 | Correct | 69 ms | 12328 KB | Output is correct |
13 | Correct | 62 ms | 11640 KB | Output is correct |
14 | Correct | 45 ms | 10180 KB | Output is correct |
15 | Correct | 73 ms | 12664 KB | Output is correct |
16 | Incorrect | 71 ms | 12024 KB | Output isn't correct |
17 | Correct | 62 ms | 12152 KB | Output is correct |
18 | Correct | 69 ms | 12144 KB | Output is correct |
19 | Correct | 109 ms | 14460 KB | Output is correct |
20 | Correct | 204 ms | 20472 KB | Output is correct |
21 | Correct | 104 ms | 14456 KB | Output is correct |
22 | Correct | 80 ms | 13560 KB | Output is correct |
23 | Correct | 103 ms | 14328 KB | Output is correct |
24 | Correct | 96 ms | 14216 KB | Output is correct |
25 | Correct | 104 ms | 13992 KB | Output is correct |
26 | Correct | 93 ms | 13560 KB | Output is correct |
27 | Correct | 116 ms | 14328 KB | Output is correct |
28 | Correct | 129 ms | 14456 KB | Output is correct |
29 | Correct | 143 ms | 16504 KB | Output is correct |
30 | Correct | 263 ms | 21248 KB | Output is correct |
31 | Correct | 128 ms | 15484 KB | Output is correct |
32 | Correct | 97 ms | 14328 KB | Output is correct |
33 | Correct | 95 ms | 14584 KB | Output is correct |
34 | Correct | 131 ms | 15184 KB | Output is correct |
35 | Correct | 107 ms | 14584 KB | Output is correct |
36 | Correct | 102 ms | 14840 KB | Output is correct |
37 | Incorrect | 134 ms | 15224 KB | Output isn't correct |
38 | Correct | 144 ms | 15888 KB | Output is correct |
39 | Correct | 148 ms | 15736 KB | Output is correct |
40 | Correct | 256 ms | 19448 KB | Output is correct |
41 | Correct | 353 ms | 24684 KB | Output is correct |