# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
29827 | 2017-07-21T07:59:26 Z | cdemirer | 007 (CEOI14_007) | C++14 | 959 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]; } if (Dparents[SV1] == SV2) best1 = max(best1, Ddists[SV1] - Zdists[SV1] + 1); if (Dparents[SV2] == SV1) best2 = max(best2, Ddists[SV2] - Zdists[SV2] + 1); int ans = min(best1, best2); printf("%d\n", (ans!=-1?ans-1:-1)); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 0 ms | 4368 KB | Partially correct |
2 | Partially correct | 0 ms | 4368 KB | Partially correct |
3 | Partially correct | 0 ms | 4368 KB | Partially correct |
4 | Correct | 0 ms | 4368 KB | Output is correct |
5 | Correct | 0 ms | 4368 KB | Output is correct |
6 | Partially correct | 0 ms | 4368 KB | Partially correct |
7 | Partially correct | 0 ms | 4368 KB | Partially correct |
8 | Correct | 0 ms | 4368 KB | Output is correct |
9 | Partially correct | 0 ms | 4368 KB | Partially correct |
10 | Partially correct | 0 ms | 4368 KB | Partially correct |
11 | Partially correct | 0 ms | 4368 KB | Partially correct |
12 | Correct | 0 ms | 4368 KB | Output is correct |
13 | Partially correct | 0 ms | 4500 KB | Partially correct |
14 | Correct | 0 ms | 4368 KB | Output is correct |
15 | Partially correct | 0 ms | 4368 KB | Partially correct |
16 | Correct | 0 ms | 4368 KB | Output is correct |
17 | Correct | 0 ms | 4500 KB | Output is correct |
18 | Correct | 0 ms | 4500 KB | Output is correct |
19 | Partially correct | 0 ms | 4500 KB | Partially correct |
20 | Partially correct | 0 ms | 4500 KB | Partially correct |
21 | Partially correct | 0 ms | 4500 KB | Partially correct |
22 | Partially correct | 0 ms | 4500 KB | Partially correct |
23 | Partially correct | 0 ms | 4500 KB | Partially correct |
24 | Correct | 0 ms | 4500 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 113 ms | 8492 KB | Partially correct |
2 | Correct | 173 ms | 10380 KB | Output is correct |
3 | Partially correct | 126 ms | 8808 KB | Partially correct |
4 | Correct | 199 ms | 10564 KB | Output is correct |
5 | Partially correct | 109 ms | 8312 KB | Partially correct |
6 | Partially correct | 119 ms | 8984 KB | Partially correct |
7 | Partially correct | 143 ms | 9348 KB | Partially correct |
8 | Partially correct | 149 ms | 9348 KB | Partially correct |
9 | Correct | 176 ms | 9900 KB | Output is correct |
10 | Partially correct | 383 ms | 14780 KB | Partially correct |
11 | Correct | 369 ms | 13620 KB | Output is correct |
12 | Partially correct | 463 ms | 15860 KB | Partially correct |
13 | Correct | 346 ms | 14308 KB | Output is correct |
14 | Correct | 309 ms | 12768 KB | Output is correct |
15 | Partially correct | 479 ms | 16192 KB | Partially correct |
16 | Partially correct | 306 ms | 16736 KB | Partially correct |
17 | Partially correct | 336 ms | 15508 KB | Partially correct |
18 | Correct | 413 ms | 15508 KB | Output is correct |
19 | Partially correct | 429 ms | 16740 KB | Partially correct |
20 | Correct | 476 ms | 19736 KB | Output is correct |
21 | Correct | 549 ms | 20680 KB | Output is correct |
22 | Partially correct | 589 ms | 18444 KB | Partially correct |
23 | Partially correct | 623 ms | 20488 KB | Partially correct |
24 | Partially correct | 549 ms | 20324 KB | Partially correct |
25 | Correct | 573 ms | 19464 KB | Output is correct |
26 | Partially correct | 516 ms | 18628 KB | Partially correct |
27 | Partially correct | 503 ms | 20664 KB | Partially correct |
28 | Partially correct | 599 ms | 20668 KB | Partially correct |
29 | Partially correct | 576 ms | 19916 KB | Partially correct |
30 | Correct | 696 ms | 21412 KB | Output is correct |
31 | Correct | 746 ms | 23084 KB | Output is correct |
32 | Partially correct | 669 ms | 20480 KB | Partially correct |
33 | Partially correct | 683 ms | 21024 KB | Partially correct |
34 | Correct | 726 ms | 21852 KB | Output is correct |
35 | Correct | 496 ms | 21188 KB | Output is correct |
36 | Correct | 626 ms | 21864 KB | Output is correct |
37 | Partially correct | 683 ms | 24112 KB | Partially correct |
38 | Partially correct | 566 ms | 23744 KB | Partially correct |
39 | Partially correct | 843 ms | 23748 KB | Partially correct |
40 | Correct | 866 ms | 24720 KB | Output is correct |
41 | Partially correct | 959 ms | 26580 KB | Partially correct |