# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
243277 | 2020-06-30T17:26:23 Z | BamiTorabi | 007 (CEOI14_007) | C++14 | 371 ms | 18296 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[3][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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 8192 KB | Output is correct |
2 | Partially correct | 9 ms | 8064 KB | Partially correct |
3 | Correct | 9 ms | 8192 KB | Output is correct |
4 | Correct | 9 ms | 8192 KB | Output is correct |
5 | Correct | 9 ms | 8192 KB | Output is correct |
6 | Correct | 9 ms | 8192 KB | Output is correct |
7 | Correct | 9 ms | 8192 KB | Output is correct |
8 | Correct | 11 ms | 8192 KB | Output is correct |
9 | Correct | 9 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 | 10 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 | 9 ms | 8192 KB | Output is correct |
16 | Correct | 9 ms | 8192 KB | Output is correct |
17 | Correct | 9 ms | 8192 KB | Output is correct |
18 | Correct | 11 ms | 8192 KB | Output is correct |
19 | Correct | 10 ms | 8320 KB | Output is correct |
20 | Correct | 9 ms | 8064 KB | Output is correct |
21 | Correct | 9 ms | 8192 KB | Output is correct |
22 | Correct | 10 ms | 8320 KB | Output is correct |
23 | Correct | 10 ms | 8192 KB | Output is correct |
24 | Correct | 10 ms | 8192 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 36 ms | 9472 KB | Output is correct |
2 | Correct | 52 ms | 10104 KB | Output is correct |
3 | Correct | 43 ms | 9592 KB | Output is correct |
4 | Correct | 56 ms | 10104 KB | Output is correct |
5 | Correct | 35 ms | 9468 KB | Output is correct |
6 | Correct | 38 ms | 9600 KB | Output is correct |
7 | Correct | 43 ms | 9720 KB | Output is correct |
8 | Correct | 41 ms | 9728 KB | Output is correct |
9 | Correct | 55 ms | 10104 KB | Output is correct |
10 | Correct | 205 ms | 14304 KB | Output is correct |
11 | Correct | 79 ms | 11000 KB | Output is correct |
12 | Correct | 104 ms | 11768 KB | Output is correct |
13 | Correct | 97 ms | 11256 KB | Output is correct |
14 | Correct | 72 ms | 10872 KB | Output is correct |
15 | Correct | 104 ms | 11896 KB | Output is correct |
16 | Correct | 130 ms | 12024 KB | Output is correct |
17 | Correct | 104 ms | 11656 KB | Output is correct |
18 | Correct | 107 ms | 11644 KB | Output is correct |
19 | Correct | 151 ms | 12792 KB | Output is correct |
20 | Correct | 255 ms | 15724 KB | Output is correct |
21 | Correct | 152 ms | 13176 KB | Output is correct |
22 | Correct | 157 ms | 12536 KB | Output is correct |
23 | Correct | 140 ms | 13176 KB | Output is correct |
24 | Correct | 133 ms | 13072 KB | Output is correct |
25 | Correct | 135 ms | 12792 KB | Output is correct |
26 | Correct | 130 ms | 12648 KB | Output is correct |
27 | Correct | 153 ms | 13176 KB | Output is correct |
28 | Correct | 178 ms | 13176 KB | Output is correct |
29 | Correct | 178 ms | 13944 KB | Output is correct |
30 | Correct | 303 ms | 16120 KB | Output is correct |
31 | Correct | 159 ms | 13944 KB | Output is correct |
32 | Correct | 161 ms | 13176 KB | Output is correct |
33 | Partially correct | 153 ms | 13304 KB | Partially correct |
34 | Correct | 184 ms | 13604 KB | Output is correct |
35 | Correct | 145 ms | 13304 KB | Output is correct |
36 | Correct | 159 ms | 13560 KB | Output is correct |
37 | Correct | 207 ms | 14328 KB | Output is correct |
38 | Correct | 185 ms | 14072 KB | Output is correct |
39 | Correct | 248 ms | 14216 KB | Output is correct |
40 | Correct | 251 ms | 15864 KB | Output is correct |
41 | Correct | 371 ms | 18296 KB | Output is correct |