답안 #480937

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
480937 2021-10-18T20:52:15 Z peti1234 경주 (Race) (IOI11_race) C++17
100 / 100
522 ms 101504 KB
#include <bits/stdc++.h>

using namespace std;
const int c=200005;
int szint[c], ki[c];
long long dist[c], cel, ans=c;
map<long long, long long> m[c];
vector<pair<int, int> > sz[c];
bool v[c];

void unio(int a, int b) {
    int aa=ki[a], bb=ki[b], sa=m[aa].size(), sb=m[bb].size();
    long long ert=cel+2*dist[a];
    if (sa>=sb) {
        for (auto p:m[bb]) {
            long long fi=p.first, se=p.second, inv=ert-fi;
            if (m[aa].find(inv)!=m[aa].end()) {
                ans=min(ans, se+m[aa][inv]-2*szint[a]);
            }
        }
        for (auto p:m[bb]) {
            long long fi=p.first, se=p.second;
            if (m[aa].find(fi)!=m[aa].end()) {
                m[aa][fi]=min(m[aa][fi], se);
            } else {
                m[aa][fi]=se;
            }
        }
    } else {
        ki[a]=bb;
        for (auto p:m[aa]) {
            long long fi=p.first, se=p.second, inv=ert-fi;
            if (m[bb].find(inv)!=m[bb].end()) {
                ans=min(ans, se+m[bb][inv]-2*szint[a]);
            }
        }
        for (auto p:m[aa]) {
            long long fi=p.first, se=p.second;
            if (m[bb].find(fi)!=m[bb].end()) {
                m[bb][fi]=min(m[bb][fi], se);
            } else {
                m[bb][fi]=se;
            }
        }
    }
}

void dfs(int a) {
    v[a]=true;
    ki[a]=a;
    m[a][dist[a]]=szint[a];
    for (auto p:sz[a]) {
        int x=p.first, y=p.second;
        if (!v[x]) {
            szint[x]=szint[a]+1;
            dist[x]=dist[a]+y;
            dfs(x);
            unio(a, x);
        }
    }
}

int best_path(int n, int K, int H[][2], int L[]) {
    cel=K;
    for (int i=0; i<n-1; i++) {
        int a=H[i][0], b=H[i][1], c=L[i];
        a++, b++;
        sz[a].push_back({b, c});
        sz[b].push_back({a, c});
    }
    szint[1]=1;
    dfs(1);
    return (ans==c ? -1 : ans);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14412 KB Output is correct
2 Correct 10 ms 14412 KB Output is correct
3 Correct 11 ms 14408 KB Output is correct
4 Correct 11 ms 14412 KB Output is correct
5 Correct 12 ms 14364 KB Output is correct
6 Correct 12 ms 14412 KB Output is correct
7 Correct 12 ms 14412 KB Output is correct
8 Correct 12 ms 14412 KB Output is correct
9 Correct 11 ms 14412 KB Output is correct
10 Correct 10 ms 14412 KB Output is correct
11 Correct 11 ms 14344 KB Output is correct
12 Correct 10 ms 14444 KB Output is correct
13 Correct 12 ms 14412 KB Output is correct
14 Correct 10 ms 14340 KB Output is correct
15 Correct 11 ms 14412 KB Output is correct
16 Correct 11 ms 14412 KB Output is correct
17 Correct 10 ms 14384 KB Output is correct
18 Correct 10 ms 14412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14412 KB Output is correct
2 Correct 10 ms 14412 KB Output is correct
3 Correct 11 ms 14408 KB Output is correct
4 Correct 11 ms 14412 KB Output is correct
5 Correct 12 ms 14364 KB Output is correct
6 Correct 12 ms 14412 KB Output is correct
7 Correct 12 ms 14412 KB Output is correct
8 Correct 12 ms 14412 KB Output is correct
9 Correct 11 ms 14412 KB Output is correct
10 Correct 10 ms 14412 KB Output is correct
11 Correct 11 ms 14344 KB Output is correct
12 Correct 10 ms 14444 KB Output is correct
13 Correct 12 ms 14412 KB Output is correct
14 Correct 10 ms 14340 KB Output is correct
15 Correct 11 ms 14412 KB Output is correct
16 Correct 11 ms 14412 KB Output is correct
17 Correct 10 ms 14384 KB Output is correct
18 Correct 10 ms 14412 KB Output is correct
19 Correct 11 ms 14412 KB Output is correct
20 Correct 12 ms 14512 KB Output is correct
21 Correct 12 ms 14616 KB Output is correct
22 Correct 12 ms 14668 KB Output is correct
23 Correct 13 ms 14608 KB Output is correct
24 Correct 13 ms 14660 KB Output is correct
25 Correct 12 ms 14668 KB Output is correct
26 Correct 11 ms 14668 KB Output is correct
27 Correct 11 ms 14580 KB Output is correct
28 Correct 13 ms 14720 KB Output is correct
29 Correct 12 ms 14668 KB Output is correct
30 Correct 11 ms 14664 KB Output is correct
31 Correct 12 ms 14668 KB Output is correct
32 Correct 12 ms 14668 KB Output is correct
33 Correct 12 ms 14664 KB Output is correct
34 Correct 13 ms 14556 KB Output is correct
35 Correct 12 ms 14640 KB Output is correct
36 Correct 12 ms 14540 KB Output is correct
37 Correct 11 ms 14540 KB Output is correct
38 Correct 11 ms 14612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14412 KB Output is correct
2 Correct 10 ms 14412 KB Output is correct
3 Correct 11 ms 14408 KB Output is correct
4 Correct 11 ms 14412 KB Output is correct
5 Correct 12 ms 14364 KB Output is correct
6 Correct 12 ms 14412 KB Output is correct
7 Correct 12 ms 14412 KB Output is correct
8 Correct 12 ms 14412 KB Output is correct
9 Correct 11 ms 14412 KB Output is correct
10 Correct 10 ms 14412 KB Output is correct
11 Correct 11 ms 14344 KB Output is correct
12 Correct 10 ms 14444 KB Output is correct
13 Correct 12 ms 14412 KB Output is correct
14 Correct 10 ms 14340 KB Output is correct
15 Correct 11 ms 14412 KB Output is correct
16 Correct 11 ms 14412 KB Output is correct
17 Correct 10 ms 14384 KB Output is correct
18 Correct 10 ms 14412 KB Output is correct
19 Correct 144 ms 36624 KB Output is correct
20 Correct 149 ms 36432 KB Output is correct
21 Correct 146 ms 36132 KB Output is correct
22 Correct 151 ms 35728 KB Output is correct
23 Correct 194 ms 48660 KB Output is correct
24 Correct 149 ms 39108 KB Output is correct
25 Correct 114 ms 32196 KB Output is correct
26 Correct 69 ms 35980 KB Output is correct
27 Correct 223 ms 46660 KB Output is correct
28 Correct 312 ms 70088 KB Output is correct
29 Correct 310 ms 69708 KB Output is correct
30 Correct 213 ms 46660 KB Output is correct
31 Correct 212 ms 46560 KB Output is correct
32 Correct 280 ms 46684 KB Output is correct
33 Correct 280 ms 51364 KB Output is correct
34 Correct 374 ms 83300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14412 KB Output is correct
2 Correct 10 ms 14412 KB Output is correct
3 Correct 11 ms 14408 KB Output is correct
4 Correct 11 ms 14412 KB Output is correct
5 Correct 12 ms 14364 KB Output is correct
6 Correct 12 ms 14412 KB Output is correct
7 Correct 12 ms 14412 KB Output is correct
8 Correct 12 ms 14412 KB Output is correct
9 Correct 11 ms 14412 KB Output is correct
10 Correct 10 ms 14412 KB Output is correct
11 Correct 11 ms 14344 KB Output is correct
12 Correct 10 ms 14444 KB Output is correct
13 Correct 12 ms 14412 KB Output is correct
14 Correct 10 ms 14340 KB Output is correct
15 Correct 11 ms 14412 KB Output is correct
16 Correct 11 ms 14412 KB Output is correct
17 Correct 10 ms 14384 KB Output is correct
18 Correct 10 ms 14412 KB Output is correct
19 Correct 11 ms 14412 KB Output is correct
20 Correct 12 ms 14512 KB Output is correct
21 Correct 12 ms 14616 KB Output is correct
22 Correct 12 ms 14668 KB Output is correct
23 Correct 13 ms 14608 KB Output is correct
24 Correct 13 ms 14660 KB Output is correct
25 Correct 12 ms 14668 KB Output is correct
26 Correct 11 ms 14668 KB Output is correct
27 Correct 11 ms 14580 KB Output is correct
28 Correct 13 ms 14720 KB Output is correct
29 Correct 12 ms 14668 KB Output is correct
30 Correct 11 ms 14664 KB Output is correct
31 Correct 12 ms 14668 KB Output is correct
32 Correct 12 ms 14668 KB Output is correct
33 Correct 12 ms 14664 KB Output is correct
34 Correct 13 ms 14556 KB Output is correct
35 Correct 12 ms 14640 KB Output is correct
36 Correct 12 ms 14540 KB Output is correct
37 Correct 11 ms 14540 KB Output is correct
38 Correct 11 ms 14612 KB Output is correct
39 Correct 144 ms 36624 KB Output is correct
40 Correct 149 ms 36432 KB Output is correct
41 Correct 146 ms 36132 KB Output is correct
42 Correct 151 ms 35728 KB Output is correct
43 Correct 194 ms 48660 KB Output is correct
44 Correct 149 ms 39108 KB Output is correct
45 Correct 114 ms 32196 KB Output is correct
46 Correct 69 ms 35980 KB Output is correct
47 Correct 223 ms 46660 KB Output is correct
48 Correct 312 ms 70088 KB Output is correct
49 Correct 310 ms 69708 KB Output is correct
50 Correct 213 ms 46660 KB Output is correct
51 Correct 212 ms 46560 KB Output is correct
52 Correct 280 ms 46684 KB Output is correct
53 Correct 280 ms 51364 KB Output is correct
54 Correct 374 ms 83300 KB Output is correct
55 Correct 26 ms 17568 KB Output is correct
56 Correct 20 ms 16248 KB Output is correct
57 Correct 89 ms 33864 KB Output is correct
58 Correct 64 ms 27320 KB Output is correct
59 Correct 102 ms 42236 KB Output is correct
60 Correct 304 ms 69656 KB Output is correct
61 Correct 270 ms 50040 KB Output is correct
62 Correct 215 ms 46632 KB Output is correct
63 Correct 289 ms 46888 KB Output is correct
64 Correct 522 ms 101504 KB Output is correct
65 Correct 510 ms 99268 KB Output is correct
66 Correct 329 ms 68616 KB Output is correct
67 Correct 211 ms 40752 KB Output is correct
68 Correct 396 ms 62916 KB Output is correct
69 Correct 412 ms 68108 KB Output is correct
70 Correct 378 ms 60848 KB Output is correct