# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
101470 | 2019-03-19T02:53:36 Z | shenxy | 007 (CEOI14_007) | C++11 | 353 ms | 16988 KB |
#include <cstdio> #include <algorithm> #include <vector> #include <queue> using namespace std; const int INF = 1000000000; int main() { int N, M, s, d, a, b, u, v; scanf("%d %d", &N, &M); scanf("%d %d %d %d", &s, &d, &a, &b); s -= 1, d -= 1, a -= 1, b -= 1; vector<int> adjlist[N]; for (int i = 0; i < M; i++) { scanf("%d %d", &u, &v); adjlist[u - 1].push_back(v - 1); adjlist[v - 1].push_back(u - 1); } int dists[N]; fill_n(dists, N, INF); dists[s] = 0; queue<int> q; q.push(s); while (!q.empty()) { int u = q.front(); q.pop(); for (int i = 0; i < adjlist[u].size(); i++) { if (dists[adjlist[u][i]] == INF) { dists[adjlist[u][i]] = dists[u] + 1; q.push(adjlist[u][i]); } } } int distd[N]; fill_n(distd, N, INF); distd[d] = 0; q.push(d); while (!q.empty()) { int u = q.front(); q.pop(); for (int i = 0; i < adjlist[u].size(); i++) { if (distd[adjlist[u][i]] == INF) { distd[adjlist[u][i]] = distd[u] + 1; q.push(adjlist[u][i]); } } } printf("%d", min(distd[a] - dists[a], distd[b] - dists[b]) >= 0 ? min(distd[a] - dists[a], distd[b] - dists[b]): -1); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 428 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 288 KB | Output is correct |
4 | Incorrect | 2 ms | 256 KB | Output isn't correct |
5 | Incorrect | 2 ms | 256 KB | Output isn't correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 252 KB | Output is correct |
8 | Incorrect | 2 ms | 284 KB | Output isn't correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 356 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Incorrect | 2 ms | 256 KB | Output isn't correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Incorrect | 3 ms | 384 KB | Output isn't correct |
15 | Correct | 2 ms | 256 KB | Output is correct |
16 | Incorrect | 3 ms | 356 KB | Output isn't correct |
17 | Incorrect | 3 ms | 384 KB | Output isn't correct |
18 | Incorrect | 3 ms | 356 KB | Output isn't correct |
19 | Correct | 2 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 2 ms | 384 KB | Output is correct |
22 | Correct | 3 ms | 400 KB | Output is correct |
23 | Correct | 2 ms | 384 KB | Output is correct |
24 | Incorrect | 3 ms | 384 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 3344 KB | Output is correct |
2 | Incorrect | 55 ms | 4700 KB | Output isn't correct |
3 | Correct | 44 ms | 3448 KB | Output is correct |
4 | Incorrect | 39 ms | 4728 KB | Output isn't correct |
5 | Correct | 26 ms | 3244 KB | Output is correct |
6 | Correct | 26 ms | 3576 KB | Output is correct |
7 | Correct | 32 ms | 3832 KB | Output is correct |
8 | Correct | 57 ms | 3936 KB | Output is correct |
9 | Incorrect | 84 ms | 4808 KB | Output isn't correct |
10 | Correct | 189 ms | 9340 KB | Output is correct |
11 | Incorrect | 72 ms | 7032 KB | Output isn't correct |
12 | Correct | 115 ms | 8696 KB | Output is correct |
13 | Incorrect | 78 ms | 7536 KB | Output isn't correct |
14 | Correct | 67 ms | 6356 KB | Output is correct |
15 | Correct | 90 ms | 8924 KB | Output is correct |
16 | Correct | 141 ms | 9276 KB | Output is correct |
17 | Correct | 99 ms | 8416 KB | Output is correct |
18 | Incorrect | 107 ms | 8412 KB | Output isn't correct |
19 | Correct | 140 ms | 9700 KB | Output is correct |
20 | Incorrect | 236 ms | 12284 KB | Output isn't correct |
21 | Incorrect | 135 ms | 11656 KB | Output isn't correct |
22 | Correct | 110 ms | 10388 KB | Output is correct |
23 | Correct | 116 ms | 11536 KB | Output is correct |
24 | Correct | 115 ms | 11456 KB | Output is correct |
25 | Incorrect | 143 ms | 10924 KB | Output isn't correct |
26 | Correct | 121 ms | 10372 KB | Output is correct |
27 | Correct | 130 ms | 11540 KB | Output is correct |
28 | Correct | 152 ms | 11660 KB | Output is correct |
29 | Correct | 173 ms | 11780 KB | Output is correct |
30 | Incorrect | 303 ms | 13176 KB | Output isn't correct |
31 | Incorrect | 159 ms | 13216 KB | Output isn't correct |
32 | Correct | 162 ms | 11432 KB | Output is correct |
33 | Correct | 139 ms | 11928 KB | Output is correct |
34 | Incorrect | 147 ms | 12376 KB | Output isn't correct |
35 | Incorrect | 134 ms | 12004 KB | Output isn't correct |
36 | Incorrect | 147 ms | 12296 KB | Output isn't correct |
37 | Correct | 201 ms | 13816 KB | Output is correct |
38 | Correct | 163 ms | 13412 KB | Output is correct |
39 | Correct | 215 ms | 13484 KB | Output is correct |
40 | Incorrect | 266 ms | 14760 KB | Output isn't correct |
41 | Correct | 353 ms | 16988 KB | Output is correct |