답안 #674253

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674253 2022-12-23T14:31:11 Z Megumin2006 경주 (Race) (IOI11_race) C++14
43 / 100
444 ms 104140 KB
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define ed '\n'
#define pb push_back
#define ii pair<ll,ll>
#define fi first
#define se second

using namespace std;

const ll N = 2e5 + 10;
ii lazy[N];
vector<ii> g[N];
ll n, k, ans = 1e18;
map<ll, ll> f[N];

void Merge(ll u, ll v) {
    if (f[u].size() < f[v].size()) {
        swap(lazy[u], lazy[v]);
        f[u].swap(f[v]);
    }
    for(pair<ll, ll> tmp: f[v]) {
        ll num = tmp.fi + lazy[v].fi;
        ll Min = tmp.se + lazy[v].se;

        auto t = f[u].find(k - num - lazy[u].fi);
        if (t != f[u].end()) {
            if (t->se + Min + lazy[u].se < ans) {
                ans = t->se + Min + lazy[u].se;
            }
        }

        if (f[u][num - lazy[u].fi] == 0) f[u][num - lazy[u].fi] = Min - lazy[u].se;
        else {
            if (Min - lazy[u].se < f[u][num - lazy[u].fi]) {
                f[u][num - lazy[u].fi] = Min - lazy[u].se;
            }
        }
    }
}

void dfs(ll u, ll p, ll val) {
    f[u][0] = 0;
    for(ii &e: g[u]) if (e.fi != p) {
        dfs(e.fi, u, e.se);
        Merge(u, e.fi);
    }
    lazy[u].fi += val;
    lazy[u].se ++;
}

ll best_path(int N, int K, int H[][2], int L[]) {
    n = N, k = K;
    for(ll i=0;i<n-1;i++)
    {
        g[H[i][0]].pb({H[i][1],L[i]});
        g[H[i][1]].pb({H[i][0],L[i]});
    }

    dfs(0, -1, 0);
    if (ans == 1e18) ans = -1;
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14432 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14384 KB Output is correct
7 Correct 7 ms 14312 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14416 KB Output is correct
10 Correct 9 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 8 ms 14432 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 9 ms 14316 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14432 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14384 KB Output is correct
7 Correct 7 ms 14312 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14416 KB Output is correct
10 Correct 9 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 8 ms 14432 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 9 ms 14316 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 7 ms 14292 KB Output is correct
20 Correct 8 ms 14432 KB Output is correct
21 Correct 8 ms 14612 KB Output is correct
22 Correct 10 ms 14632 KB Output is correct
23 Correct 8 ms 14712 KB Output is correct
24 Correct 8 ms 14676 KB Output is correct
25 Correct 10 ms 14648 KB Output is correct
26 Correct 9 ms 14676 KB Output is correct
27 Correct 8 ms 14568 KB Output is correct
28 Correct 8 ms 14676 KB Output is correct
29 Correct 8 ms 14676 KB Output is correct
30 Correct 8 ms 14676 KB Output is correct
31 Correct 9 ms 14684 KB Output is correct
32 Correct 8 ms 14676 KB Output is correct
33 Correct 10 ms 14692 KB Output is correct
34 Correct 9 ms 14540 KB Output is correct
35 Correct 8 ms 14576 KB Output is correct
36 Correct 8 ms 14640 KB Output is correct
37 Correct 7 ms 14548 KB Output is correct
38 Correct 8 ms 14644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14432 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14384 KB Output is correct
7 Correct 7 ms 14312 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14416 KB Output is correct
10 Correct 9 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 8 ms 14432 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 9 ms 14316 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 140 ms 37760 KB Output is correct
20 Correct 150 ms 37756 KB Output is correct
21 Correct 126 ms 37588 KB Output is correct
22 Correct 123 ms 37116 KB Output is correct
23 Correct 158 ms 50012 KB Output is correct
24 Correct 161 ms 39968 KB Output is correct
25 Correct 109 ms 32844 KB Output is correct
26 Correct 55 ms 35864 KB Output is correct
27 Correct 184 ms 49560 KB Output is correct
28 Correct 265 ms 69968 KB Output is correct
29 Correct 280 ms 69700 KB Output is correct
30 Correct 205 ms 49632 KB Output is correct
31 Correct 189 ms 49536 KB Output is correct
32 Correct 272 ms 49612 KB Output is correct
33 Correct 262 ms 54284 KB Output is correct
34 Correct 390 ms 86256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14432 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14384 KB Output is correct
7 Correct 7 ms 14312 KB Output is correct
8 Correct 7 ms 14420 KB Output is correct
9 Correct 7 ms 14416 KB Output is correct
10 Correct 9 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 8 ms 14432 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 9 ms 14316 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 7 ms 14292 KB Output is correct
20 Correct 8 ms 14432 KB Output is correct
21 Correct 8 ms 14612 KB Output is correct
22 Correct 10 ms 14632 KB Output is correct
23 Correct 8 ms 14712 KB Output is correct
24 Correct 8 ms 14676 KB Output is correct
25 Correct 10 ms 14648 KB Output is correct
26 Correct 9 ms 14676 KB Output is correct
27 Correct 8 ms 14568 KB Output is correct
28 Correct 8 ms 14676 KB Output is correct
29 Correct 8 ms 14676 KB Output is correct
30 Correct 8 ms 14676 KB Output is correct
31 Correct 9 ms 14684 KB Output is correct
32 Correct 8 ms 14676 KB Output is correct
33 Correct 10 ms 14692 KB Output is correct
34 Correct 9 ms 14540 KB Output is correct
35 Correct 8 ms 14576 KB Output is correct
36 Correct 8 ms 14640 KB Output is correct
37 Correct 7 ms 14548 KB Output is correct
38 Correct 8 ms 14644 KB Output is correct
39 Correct 140 ms 37760 KB Output is correct
40 Correct 150 ms 37756 KB Output is correct
41 Correct 126 ms 37588 KB Output is correct
42 Correct 123 ms 37116 KB Output is correct
43 Correct 158 ms 50012 KB Output is correct
44 Correct 161 ms 39968 KB Output is correct
45 Correct 109 ms 32844 KB Output is correct
46 Correct 55 ms 35864 KB Output is correct
47 Correct 184 ms 49560 KB Output is correct
48 Correct 265 ms 69968 KB Output is correct
49 Correct 280 ms 69700 KB Output is correct
50 Correct 205 ms 49632 KB Output is correct
51 Correct 189 ms 49536 KB Output is correct
52 Correct 272 ms 49612 KB Output is correct
53 Correct 262 ms 54284 KB Output is correct
54 Correct 390 ms 86256 KB Output is correct
55 Correct 25 ms 17712 KB Output is correct
56 Correct 15 ms 16340 KB Output is correct
57 Correct 100 ms 35292 KB Output is correct
58 Correct 53 ms 28116 KB Output is correct
59 Correct 80 ms 42156 KB Output is correct
60 Correct 292 ms 69708 KB Output is correct
61 Correct 219 ms 53000 KB Output is correct
62 Correct 177 ms 49580 KB Output is correct
63 Correct 289 ms 49628 KB Output is correct
64 Incorrect 444 ms 104140 KB Output isn't correct
65 Halted 0 ms 0 KB -