# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
243280 | 2020-06-30T17:30:39 Z | BamiTorabi | 007 (CEOI14_007) | C++14 | 361 ms | 18040 KB |
//Sasayego! Sasayego! Shinzou wo Sasageyo! #include <iostream> #include <iomanip> #include <algorithm> #include <cmath> #include <ctime> #include <cstring> #include <vector> #include <set> #include <map> #include <stack> #include <queue> #include <deque> #include <numeric> #include <bitset> #include <ctime> #define debug(x) cerr << #x << " = " << x << endl #define lid (id << 1) #define rid (lid ^ 1) using namespace std; typedef long long ll; typedef long double ld; typedef pair <ll, ll> pll; typedef pair <int, int> pii; const int maxN = 2e5 + 5; const ll INF = 1e18; const ll MOD = 1e9 + 7; int dist[4][maxN]; queue <int> Q; vector <int> G[maxN]; void BFS(int ix, int st){ dist[ix][st] = 0; Q.push(st); while (!Q.empty()){ int v = Q.front(); Q.pop(); for (int u : G[v]) if (dist[ix][u] > dist[ix][v] + 1){ dist[ix][u] = dist[ix][v] + 1; Q.push(u); } } return; } int main(){ time_t START = clock(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); memset(dist, 63, sizeof dist); int n, m, s, t, a, b; scanf("%d%d%d%d%d%d", &n, &m, &s, &t, &a, &b); while (m--){ int u, v; scanf("%d%d", &u, &v); G[u].push_back(v); G[v].push_back(u); } BFS(0, s); BFS(1, t); BFS(2, a); BFS(3, b); if (dist[2][t] < dist[2][s] || dist[3][t] < dist[3][s]) return printf("-1\n"), 0; if (dist[2][t] - dist[2][s] != dist[3][t] - dist[3][s]) return printf("%d\n", min(dist[2][t] - dist[2][s], dist[3][t] - dist[3][s])), 0; int mns = n, mnt = n; for (int i = 1; i <= n; i++){ if (dist[0][i] + dist[2][i] == dist[2][s] && dist[0][i] + dist[3][i] == dist[3][s]) mns = min(mns, dist[2][i]); if (dist[1][i] + dist[2][i] == dist[2][t] && dist[1][i] + dist[3][i] == dist[3][t]) mnt = min(mnt, dist[2][i]); } printf("%d\n", dist[2][t] - dist[2][s] - (mnt < mns)); time_t FINISH = clock(); cerr << "Execution time: " << (ld)(FINISH - START) / CLOCKS_PER_SEC * 1000.0 << " milliseconds.\n"; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 8192 KB | Output is correct |
2 | Correct | 10 ms | 8192 KB | Output is correct |
3 | Correct | 9 ms | 8192 KB | Output is correct |
4 | Correct | 9 ms | 8192 KB | Output is correct |
5 | Correct | 9 ms | 8320 KB | Output is correct |
6 | Correct | 9 ms | 8192 KB | Output is correct |
7 | Correct | 9 ms | 8192 KB | Output is correct |
8 | Correct | 9 ms | 8192 KB | Output is correct |
9 | Correct | 10 ms | 8192 KB | Output is correct |
10 | Correct | 9 ms | 8192 KB | Output is correct |
11 | Correct | 9 ms | 8192 KB | Output is correct |
12 | Correct | 9 ms | 8192 KB | Output is correct |
13 | Correct | 9 ms | 8192 KB | Output is correct |
14 | Correct | 9 ms | 8192 KB | Output is correct |
15 | Correct | 10 ms | 8192 KB | Output is correct |
16 | Correct | 9 ms | 8192 KB | Output is correct |
17 | Correct | 11 ms | 8192 KB | Output is correct |
18 | Correct | 9 ms | 8192 KB | Output is correct |
19 | Correct | 9 ms | 8192 KB | Output is correct |
20 | Correct | 9 ms | 8192 KB | Output is correct |
21 | Correct | 9 ms | 8192 KB | Output is correct |
22 | Correct | 10 ms | 8192 KB | Output is correct |
23 | Correct | 10 ms | 8192 KB | Output is correct |
24 | Correct | 10 ms | 8192 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 36 ms | 9472 KB | Output is correct |
2 | Correct | 47 ms | 9984 KB | Output is correct |
3 | Correct | 36 ms | 9472 KB | Output is correct |
4 | Correct | 64 ms | 10232 KB | Output is correct |
5 | Correct | 34 ms | 9336 KB | Output is correct |
6 | Correct | 35 ms | 9600 KB | Output is correct |
7 | Correct | 39 ms | 9720 KB | Output is correct |
8 | Correct | 43 ms | 9720 KB | Output is correct |
9 | Correct | 55 ms | 10232 KB | Output is correct |
10 | Correct | 192 ms | 14328 KB | Output is correct |
11 | Correct | 74 ms | 11000 KB | Output is correct |
12 | Correct | 105 ms | 11772 KB | Output is correct |
13 | Correct | 124 ms | 11260 KB | Output is correct |
14 | Correct | 71 ms | 10744 KB | Output is correct |
15 | Correct | 94 ms | 11768 KB | Output is correct |
16 | Correct | 108 ms | 12024 KB | Output is correct |
17 | Correct | 91 ms | 11640 KB | Output is correct |
18 | Correct | 96 ms | 11592 KB | Output is correct |
19 | Correct | 151 ms | 12792 KB | Output is correct |
20 | Correct | 246 ms | 15736 KB | Output is correct |
21 | Correct | 141 ms | 13180 KB | Output is correct |
22 | Correct | 118 ms | 12536 KB | Output is correct |
23 | Correct | 135 ms | 13176 KB | Output is correct |
24 | Correct | 129 ms | 13048 KB | Output is correct |
25 | Correct | 131 ms | 12824 KB | Output is correct |
26 | Correct | 129 ms | 12616 KB | Output is correct |
27 | Correct | 145 ms | 13176 KB | Output is correct |
28 | Correct | 160 ms | 13176 KB | Output is correct |
29 | Correct | 180 ms | 14204 KB | Output is correct |
30 | Correct | 262 ms | 16120 KB | Output is correct |
31 | Correct | 163 ms | 13944 KB | Output is correct |
32 | Correct | 154 ms | 13176 KB | Output is correct |
33 | Correct | 160 ms | 13280 KB | Output is correct |
34 | Correct | 186 ms | 13688 KB | Output is correct |
35 | Correct | 143 ms | 13432 KB | Output is correct |
36 | Correct | 151 ms | 13688 KB | Output is correct |
37 | Correct | 199 ms | 14328 KB | Output is correct |
38 | Correct | 195 ms | 14072 KB | Output is correct |
39 | Correct | 225 ms | 14072 KB | Output is correct |
40 | Correct | 262 ms | 15852 KB | Output is correct |
41 | Correct | 361 ms | 18040 KB | Output is correct |