# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
155933 | 2019-10-02T05:43:44 Z | Akashi | 007 (CEOI14_007) | C++14 | 434 ms | 17912 KB |
#include <bits/stdc++.h> using namespace std; int n, m; bool viz[200005]; int s, d, a, b; int da[200005], db[200005], ds[200005], dd[200005]; queue <int> q; vector <int> v[200005]; void bfs(int nod, int d[]){ for(int i = 1; i <= n ; ++i) d[i] = 1e9; memset(viz, 0, sizeof(viz)); q.push(nod); d[nod] = 0; viz[nod] = 1; while(!q.empty()){ int nod = q.front(); q.pop(); for(auto it : v[nod]){ if(viz[it]) continue ; q.push(it); viz[it] = 1; d[it] = d[nod] + 1; } } } int main() { // freopen("1.in", "r", stdin); scanf("%d%d", &n, &m); scanf("%d%d%d%d", &s, &d, &a, &b); int x, y; for(int i = 1; i <= m ; ++i){ scanf("%d%d", &x, &y); v[x].push_back(y); v[y].push_back(x); } bfs(a, da); bfs(b, db); bfs(s, ds); bfs(d, dd); if(dd[b] < ds[b] || dd[a] < ds[a]){ printf("-1"); return 0; } int tmp = -1; if(dd[b] - ds[b] != dd[a] - ds[a]) tmp = min(dd[b] - ds[b], dd[a] - ds[a]); else{ int dif = min(dd[b] - ds[b], dd[a] - ds[a]), nr1 = 0, nr2 = 0; for(int i = 1; i <= n ; ++i) if(da[i] == db[i] && da[i] + ds[i] == ds[a]) nr1 = max(nr1, ds[i]); for(int i = 1; i <= n ; ++i) if(da[i] == db[i] && da[i] + dd[i] == dd[a]) nr2 = max(nr2, dd[i]); if(nr1 > nr2 - dif) tmp = min(dd[b] - ds[b], dd[a] - ds[a]); else tmp = min(dd[b] - ds[b], dd[a] - ds[a]) - 1; } printf("%d", tmp); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 5240 KB | Output is correct |
2 | Correct | 6 ms | 5240 KB | Output is correct |
3 | Partially correct | 6 ms | 5240 KB | Partially correct |
4 | Correct | 6 ms | 5240 KB | Output is correct |
5 | Correct | 6 ms | 5240 KB | Output is correct |
6 | Partially correct | 6 ms | 5240 KB | Partially correct |
7 | Partially correct | 6 ms | 5240 KB | Partially correct |
8 | Correct | 6 ms | 5240 KB | Output is correct |
9 | Partially correct | 6 ms | 5240 KB | Partially correct |
10 | Correct | 6 ms | 5240 KB | Output is correct |
11 | Correct | 6 ms | 5240 KB | Output is correct |
12 | Correct | 6 ms | 5240 KB | Output is correct |
13 | Partially correct | 7 ms | 5212 KB | Partially correct |
14 | Correct | 6 ms | 5240 KB | Output is correct |
15 | Correct | 6 ms | 5240 KB | Output is correct |
16 | Correct | 7 ms | 5240 KB | Output is correct |
17 | Correct | 7 ms | 5240 KB | Output is correct |
18 | Correct | 7 ms | 5240 KB | Output is correct |
19 | Partially correct | 7 ms | 5340 KB | Partially correct |
20 | Correct | 7 ms | 5240 KB | Output is correct |
21 | Correct | 6 ms | 5240 KB | Output is correct |
22 | Correct | 7 ms | 5240 KB | Output is correct |
23 | Partially correct | 7 ms | 5212 KB | Partially correct |
24 | Correct | 7 ms | 5240 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 36 ms | 7160 KB | Output is correct |
2 | Correct | 47 ms | 8056 KB | Output is correct |
3 | Partially correct | 40 ms | 7164 KB | Partially correct |
4 | Correct | 56 ms | 8184 KB | Output is correct |
5 | Correct | 35 ms | 7032 KB | Output is correct |
6 | Correct | 39 ms | 7288 KB | Output is correct |
7 | Correct | 42 ms | 7544 KB | Output is correct |
8 | Correct | 46 ms | 7484 KB | Output is correct |
9 | Correct | 54 ms | 7928 KB | Output is correct |
10 | Partially correct | 190 ms | 12448 KB | Partially correct |
11 | Correct | 94 ms | 9560 KB | Output is correct |
12 | Partially correct | 110 ms | 10492 KB | Partially correct |
13 | Correct | 96 ms | 9720 KB | Output is correct |
14 | Correct | 79 ms | 9080 KB | Output is correct |
15 | Correct | 121 ms | 10672 KB | Output is correct |
16 | Correct | 109 ms | 11000 KB | Output is correct |
17 | Correct | 106 ms | 10308 KB | Output is correct |
18 | Correct | 97 ms | 10360 KB | Output is correct |
19 | Partially correct | 138 ms | 11640 KB | Partially correct |
20 | Correct | 244 ms | 14508 KB | Output is correct |
21 | Correct | 170 ms | 12896 KB | Output is correct |
22 | Partially correct | 153 ms | 11768 KB | Partially correct |
23 | Correct | 153 ms | 12660 KB | Output is correct |
24 | Partially correct | 137 ms | 12492 KB | Partially correct |
25 | Correct | 127 ms | 12152 KB | Output is correct |
26 | Correct | 125 ms | 11976 KB | Output is correct |
27 | Correct | 176 ms | 12792 KB | Output is correct |
28 | Correct | 203 ms | 12920 KB | Output is correct |
29 | Partially correct | 190 ms | 13228 KB | Partially correct |
30 | Correct | 273 ms | 15156 KB | Output is correct |
31 | Correct | 210 ms | 13900 KB | Output is correct |
32 | Partially correct | 155 ms | 12792 KB | Partially correct |
33 | Correct | 165 ms | 13020 KB | Output is correct |
34 | Correct | 183 ms | 13276 KB | Output is correct |
35 | Correct | 174 ms | 13048 KB | Output is correct |
36 | Correct | 179 ms | 13392 KB | Output is correct |
37 | Correct | 213 ms | 14328 KB | Output is correct |
38 | Correct | 272 ms | 14160 KB | Output is correct |
39 | Correct | 246 ms | 14200 KB | Output is correct |
40 | Correct | 290 ms | 15716 KB | Output is correct |
41 | Partially correct | 434 ms | 17912 KB | Partially correct |