# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29821 | 2017-07-21T07:55:39 Z | cdemirer | 007 (CEOI14_007) | C++14 | 926 ms | 26580 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> llp; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vii> vvii; #define mp(x, y) make_pair(x, y) #define pb(x) push_back(x) int N, M; int Z, D, SV1, SV2; vvi edges; int Ddists[200000], Zdists[200000]; int Dparents[200000]; void dijsktra(int *dists, int s) { set<ii> S; for (int i = 0; i < N; i++) { if (i == s) { dists[i] = 0; S.insert(mp(dists[i], i)); continue; } dists[i] = (int)1e9; S.insert(mp(dists[i], i)); } while ( ! S.empty() ) { ii x = *S.begin(); S.erase(S.begin()); for (int i = 0; i < edges[x.second].size(); i++) { if (dists[x.second] + 1 < dists[edges[x.second][i]]) { S.erase(mp(dists[edges[x.second][i]], edges[x.second][i])); dists[edges[x.second][i]] = dists[x.second] + 1; if (s == D) Dparents[edges[x.second][i]] = x.second; S.insert(mp(dists[edges[x.second][i]], edges[x.second][i])); } } } } int main(int argc, char **argv) { //freopen("input", "r", stdin); //freopen("output", "w", stdout); scanf("%d%d", &N, &M); scanf("%d%d%d%d", &Z, &D, &SV1, &SV2); Z--; D--; SV1--; SV2--; edges.resize(N); for (int i = 0; i < M; i++) { int a, b; scanf("%d%d", &a, &b); a--, b--; edges[a].pb(b); edges[b].pb(a); } Dparents[D] = -1; dijsktra(Ddists, D); dijsktra(Zdists, Z); int best1 = -1; int best2 = -1; int x = SV1; while (x != -1) { //if (x) cerr << x << endl; int fark = Ddists[x] - Zdists[x]; best1 = max(best1, fark); x = Dparents[x]; } x = SV2; while (x != -1) { int fark = Ddists[x] - Zdists[x]; best2 = max(best2, fark); x = Dparents[x]; } best2 = max(best2, Ddists[SV1] - Zdists[SV1] + 1); best1 = max(best1, Ddists[SV2] - Zdists[SV2] + 1); int ans = min(best1, best2); printf("%d\n", (ans!=-1?ans-1:-1)); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 4368 KB | Output is correct |
2 | Correct | 0 ms | 4368 KB | Output is correct |
3 | Correct | 0 ms | 4368 KB | Output is correct |
4 | Incorrect | 0 ms | 4368 KB | Output isn't correct |
5 | Incorrect | 0 ms | 4368 KB | Output isn't correct |
6 | Correct | 0 ms | 4368 KB | Output is correct |
7 | Correct | 0 ms | 4368 KB | Output is correct |
8 | Incorrect | 0 ms | 4368 KB | Output isn't correct |
9 | Correct | 0 ms | 4368 KB | Output is correct |
10 | Correct | 0 ms | 4368 KB | Output is correct |
11 | Correct | 0 ms | 4368 KB | Output is correct |
12 | Incorrect | 0 ms | 4368 KB | Output isn't correct |
13 | Correct | 0 ms | 4500 KB | Output is correct |
14 | Incorrect | 0 ms | 4368 KB | Output isn't correct |
15 | Correct | 0 ms | 4368 KB | Output is correct |
16 | Incorrect | 0 ms | 4368 KB | Output isn't correct |
17 | Incorrect | 0 ms | 4500 KB | Output isn't correct |
18 | Incorrect | 0 ms | 4500 KB | Output isn't correct |
19 | Correct | 0 ms | 4500 KB | Output is correct |
20 | Correct | 0 ms | 4500 KB | Output is correct |
21 | Incorrect | 0 ms | 4500 KB | Output isn't correct |
22 | Correct | 0 ms | 4500 KB | Output is correct |
23 | Correct | 0 ms | 4500 KB | Output is correct |
24 | Incorrect | 0 ms | 4500 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 113 ms | 8492 KB | Output is correct |
2 | Incorrect | 173 ms | 10380 KB | Output isn't correct |
3 | Correct | 123 ms | 8808 KB | Output is correct |
4 | Incorrect | 179 ms | 10564 KB | Output isn't correct |
5 | Incorrect | 99 ms | 8312 KB | Output isn't correct |
6 | Incorrect | 119 ms | 8984 KB | Output isn't correct |
7 | Correct | 156 ms | 9348 KB | Output is correct |
8 | Correct | 146 ms | 9348 KB | Output is correct |
9 | Incorrect | 153 ms | 9900 KB | Output isn't correct |
10 | Correct | 376 ms | 14780 KB | Output is correct |
11 | Incorrect | 316 ms | 13620 KB | Output isn't correct |
12 | Correct | 323 ms | 15860 KB | Output is correct |
13 | Incorrect | 363 ms | 14308 KB | Output isn't correct |
14 | Correct | 276 ms | 12768 KB | Output is correct |
15 | Correct | 466 ms | 16192 KB | Output is correct |
16 | Incorrect | 449 ms | 16736 KB | Output isn't correct |
17 | Correct | 299 ms | 15508 KB | Output is correct |
18 | Incorrect | 303 ms | 15508 KB | Output isn't correct |
19 | Correct | 346 ms | 16740 KB | Output is correct |
20 | Incorrect | 439 ms | 19736 KB | Output isn't correct |
21 | Incorrect | 463 ms | 20680 KB | Output isn't correct |
22 | Correct | 396 ms | 18444 KB | Output is correct |
23 | Correct | 433 ms | 20488 KB | Output is correct |
24 | Correct | 576 ms | 20324 KB | Output is correct |
25 | Incorrect | 606 ms | 19464 KB | Output isn't correct |
26 | Correct | 576 ms | 18628 KB | Output is correct |
27 | Correct | 703 ms | 20664 KB | Output is correct |
28 | Correct | 743 ms | 20668 KB | Output is correct |
29 | Correct | 506 ms | 19916 KB | Output is correct |
30 | Incorrect | 539 ms | 21412 KB | Output isn't correct |
31 | Incorrect | 749 ms | 23084 KB | Output isn't correct |
32 | Correct | 703 ms | 20480 KB | Output is correct |
33 | Correct | 676 ms | 21024 KB | Output is correct |
34 | Incorrect | 793 ms | 21852 KB | Output isn't correct |
35 | Incorrect | 716 ms | 21188 KB | Output isn't correct |
36 | Incorrect | 656 ms | 21864 KB | Output isn't correct |
37 | Incorrect | 919 ms | 24112 KB | Output isn't correct |
38 | Correct | 833 ms | 23744 KB | Output is correct |
39 | Correct | 849 ms | 23748 KB | Output is correct |
40 | Incorrect | 926 ms | 24720 KB | Output isn't correct |
41 | Correct | 849 ms | 26580 KB | Output is correct |