답안 #650751

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
650751 2022-10-15T08:10:26 Z DeMen100ns 경주 (Race) (IOI11_race) C++17
100 / 100
603 ms 116452 KB
/*
Author : DeMen100ns (a.k.a Vo Khac Trieu)
School : VNU-HCM High school for the Gifted
fuck you adhoc
*/

#include <bits/stdc++.h>

#include "race.h"

using namespace std;

//#define int long long

const int N = 2e5 + 5;
const long long INF = 1e18 + 7;
const int MAXA = 1e9;
const int B = sqrt(N) + 5;

vector <pair<int, int>> a[N];
int h[N], e[N], n, k;
int ans = MAXA;
map <int, int> m[N];

void dfs(int u, int par = -1){
    for(pair<int, int> st : a[u]){
        int i = st.first, w = st.second;
        if (i == par) continue;

        e[i] = e[u] + 1;
        h[i] = h[u] + w;

        dfs(i, u);

        if (m[u].empty()){
            swap(m[u], m[i]);
            if (m[u].find(k + h[u]) != m[u].end()) ans = min(ans, m[u][k + h[u]] - e[u]);

            if (m[u].find(h[u]) != m[u].end()) m[u][h[u]] = min(m[u][h[u]], e[u]);
            else m[u][h[u]] = e[u];
        } else {
            for(pair<int, int> st : m[i]){
                int h1 = st.first, e1 = st.second;
                //h1 + x - 2 * h[u] = k

                if (m[u].find(k - h1 + 2 * h[u]) != m[u].end()){
                    ans = min(ans, e1 + m[u][k - h1 + 2 * h[u]] - 2 * e[u]);
                }
            }

            for(pair<int, int> st : m[i]){
                int h1 = st.first, e1 = st.second;

                if (m[u].find(h1) != m[u].end()){
                    m[u][h1] = min(m[u][h1], e1);
                } else m[u][h1] = e1;
            }
        }
    }

    if (m[u].empty()) m[u][h[u]] = e[u];
}

int best_path(int N, int K, int H[][2], int L[]){
    n = N; k = K;
    for(int i = 0; i < N - 1; ++i){
        a[H[i][0]].push_back({H[i][1], L[i]});
        a[H[i][1]].push_back({H[i][0], L[i]});
    }
    for(int i = 0; i < N; ++i){
        sort(a[i].begin(), a[i].end(), [](pair<int, int> v1, pair<int, int> v2){return a[v1.first].size() > a[v2.first].size();});
    }

    dfs(0);

    if (ans == MAXA) return -1;
    else return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14412 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14408 KB Output is correct
5 Correct 7 ms 14400 KB Output is correct
6 Correct 7 ms 14408 KB Output is correct
7 Correct 8 ms 14404 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14404 KB Output is correct
12 Correct 8 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 7 ms 14404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14412 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14408 KB Output is correct
5 Correct 7 ms 14400 KB Output is correct
6 Correct 7 ms 14408 KB Output is correct
7 Correct 8 ms 14404 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14404 KB Output is correct
12 Correct 8 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 7 ms 14404 KB Output is correct
19 Correct 8 ms 14420 KB Output is correct
20 Correct 8 ms 14404 KB Output is correct
21 Correct 8 ms 14548 KB Output is correct
22 Correct 8 ms 14672 KB Output is correct
23 Correct 10 ms 14804 KB Output is correct
24 Correct 8 ms 14672 KB Output is correct
25 Correct 9 ms 14664 KB Output is correct
26 Correct 9 ms 14608 KB Output is correct
27 Correct 8 ms 14548 KB Output is correct
28 Correct 8 ms 14548 KB Output is correct
29 Correct 8 ms 14552 KB Output is correct
30 Correct 8 ms 14672 KB Output is correct
31 Correct 9 ms 14548 KB Output is correct
32 Correct 8 ms 14540 KB Output is correct
33 Correct 9 ms 14668 KB Output is correct
34 Correct 8 ms 14548 KB Output is correct
35 Correct 8 ms 14548 KB Output is correct
36 Correct 8 ms 14548 KB Output is correct
37 Correct 9 ms 14548 KB Output is correct
38 Correct 8 ms 14548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14412 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14408 KB Output is correct
5 Correct 7 ms 14400 KB Output is correct
6 Correct 7 ms 14408 KB Output is correct
7 Correct 8 ms 14404 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14404 KB Output is correct
12 Correct 8 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 7 ms 14404 KB Output is correct
19 Correct 113 ms 31328 KB Output is correct
20 Correct 114 ms 31476 KB Output is correct
21 Correct 114 ms 30784 KB Output is correct
22 Correct 114 ms 30708 KB Output is correct
23 Correct 146 ms 40012 KB Output is correct
24 Correct 118 ms 34508 KB Output is correct
25 Correct 81 ms 29516 KB Output is correct
26 Correct 55 ms 36508 KB Output is correct
27 Correct 191 ms 38440 KB Output is correct
28 Correct 256 ms 66668 KB Output is correct
29 Correct 332 ms 74536 KB Output is correct
30 Correct 187 ms 37028 KB Output is correct
31 Correct 200 ms 38348 KB Output is correct
32 Correct 242 ms 38296 KB Output is correct
33 Correct 232 ms 43324 KB Output is correct
34 Correct 473 ms 95012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14412 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14408 KB Output is correct
5 Correct 7 ms 14400 KB Output is correct
6 Correct 7 ms 14408 KB Output is correct
7 Correct 8 ms 14404 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14404 KB Output is correct
12 Correct 8 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 7 ms 14404 KB Output is correct
19 Correct 8 ms 14420 KB Output is correct
20 Correct 8 ms 14404 KB Output is correct
21 Correct 8 ms 14548 KB Output is correct
22 Correct 8 ms 14672 KB Output is correct
23 Correct 10 ms 14804 KB Output is correct
24 Correct 8 ms 14672 KB Output is correct
25 Correct 9 ms 14664 KB Output is correct
26 Correct 9 ms 14608 KB Output is correct
27 Correct 8 ms 14548 KB Output is correct
28 Correct 8 ms 14548 KB Output is correct
29 Correct 8 ms 14552 KB Output is correct
30 Correct 8 ms 14672 KB Output is correct
31 Correct 9 ms 14548 KB Output is correct
32 Correct 8 ms 14540 KB Output is correct
33 Correct 9 ms 14668 KB Output is correct
34 Correct 8 ms 14548 KB Output is correct
35 Correct 8 ms 14548 KB Output is correct
36 Correct 8 ms 14548 KB Output is correct
37 Correct 9 ms 14548 KB Output is correct
38 Correct 8 ms 14548 KB Output is correct
39 Correct 113 ms 31328 KB Output is correct
40 Correct 114 ms 31476 KB Output is correct
41 Correct 114 ms 30784 KB Output is correct
42 Correct 114 ms 30708 KB Output is correct
43 Correct 146 ms 40012 KB Output is correct
44 Correct 118 ms 34508 KB Output is correct
45 Correct 81 ms 29516 KB Output is correct
46 Correct 55 ms 36508 KB Output is correct
47 Correct 191 ms 38440 KB Output is correct
48 Correct 256 ms 66668 KB Output is correct
49 Correct 332 ms 74536 KB Output is correct
50 Correct 187 ms 37028 KB Output is correct
51 Correct 200 ms 38348 KB Output is correct
52 Correct 242 ms 38296 KB Output is correct
53 Correct 232 ms 43324 KB Output is correct
54 Correct 473 ms 95012 KB Output is correct
55 Correct 26 ms 17968 KB Output is correct
56 Correct 14 ms 15792 KB Output is correct
57 Correct 68 ms 28868 KB Output is correct
58 Correct 63 ms 25916 KB Output is correct
59 Correct 79 ms 41164 KB Output is correct
60 Correct 299 ms 75436 KB Output is correct
61 Correct 231 ms 41080 KB Output is correct
62 Correct 195 ms 38484 KB Output is correct
63 Correct 228 ms 38820 KB Output is correct
64 Correct 603 ms 116452 KB Output is correct
65 Correct 468 ms 93772 KB Output is correct
66 Correct 295 ms 66148 KB Output is correct
67 Correct 168 ms 38872 KB Output is correct
68 Correct 353 ms 56376 KB Output is correct
69 Correct 403 ms 57172 KB Output is correct
70 Correct 400 ms 54656 KB Output is correct