답안 #1067063

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067063 2024-08-20T10:30:53 Z Thunnus 경주 (Race) (IOI11_race) C++17
100 / 100
296 ms 75092 KB
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define pii pair<int, int>
#define fi first
#define se second
#define sz(x) (int)(x).size()

const int MAXN = 2e5 + 5;
int ans = LLONG_MAX, k;
vector<map<int, int>> mp(MAXN);

inline void dfs(vector<vector<pii>> &adj, int v = 0, int p = -1, int dist = 0, int dep = 0){
    mp[v][dist] = dep;
    for(pii &u : adj[v]){
        if(u.fi == p) continue;
        dfs(adj, u.fi, v, dist + u.se, dep + 1);
        if(sz(mp[u.fi]) > sz(mp[v])) mp[v].swap(mp[u.fi]);
        for(auto &it : mp[u.fi]){
            if(mp[v].count(k - (it.fi - 2 * dist))){ // distance with lca
                ans = min(ans, mp[v][k - (it.fi - 2 * dist)] + it.se - 2 * dep);
            }
        }
        for(auto &it : mp[u.fi]){
            if(!mp[v].count(it.fi)) mp[v][it.fi] = it.se;
            else mp[v][it.fi] = min(mp[v][it.fi], it.se);
            if(it.fi - dist == k){
                ans = min(ans, it.se - dep);
            }
        }
        mp[u.fi].clear();
    } 
}

int32_t best_path(int32_t n, int32_t K, int32_t h[][2], int32_t l[]){
	k = K;
    vector<vector<pii>> adj(n);
    for(int i = 0; i < n - 1; i++){
        adj[h[i][0]].emplace_back(h[i][1], l[i]);
        adj[h[i][1]].emplace_back(h[i][0], l[i]);
    }
    dfs(adj);
    return (ans == LLONG_MAX ? -1 : ans);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9664 KB Output is correct
7 Correct 4 ms 9820 KB Output is correct
8 Correct 4 ms 9852 KB Output is correct
9 Correct 4 ms 9816 KB Output is correct
10 Correct 4 ms 9820 KB Output is correct
11 Correct 4 ms 9820 KB Output is correct
12 Correct 4 ms 9820 KB Output is correct
13 Correct 4 ms 9816 KB Output is correct
14 Correct 5 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 6 ms 9820 KB Output is correct
17 Correct 4 ms 9856 KB Output is correct
18 Correct 4 ms 9820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9664 KB Output is correct
7 Correct 4 ms 9820 KB Output is correct
8 Correct 4 ms 9852 KB Output is correct
9 Correct 4 ms 9816 KB Output is correct
10 Correct 4 ms 9820 KB Output is correct
11 Correct 4 ms 9820 KB Output is correct
12 Correct 4 ms 9820 KB Output is correct
13 Correct 4 ms 9816 KB Output is correct
14 Correct 5 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 6 ms 9820 KB Output is correct
17 Correct 4 ms 9856 KB Output is correct
18 Correct 4 ms 9820 KB Output is correct
19 Correct 4 ms 9820 KB Output is correct
20 Correct 4 ms 9820 KB Output is correct
21 Correct 4 ms 9816 KB Output is correct
22 Correct 5 ms 9820 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 5 ms 9820 KB Output is correct
25 Correct 5 ms 9820 KB Output is correct
26 Correct 6 ms 9820 KB Output is correct
27 Correct 4 ms 9844 KB Output is correct
28 Correct 5 ms 9884 KB Output is correct
29 Correct 5 ms 9820 KB Output is correct
30 Correct 5 ms 9820 KB Output is correct
31 Correct 5 ms 9820 KB Output is correct
32 Correct 4 ms 9820 KB Output is correct
33 Correct 5 ms 9820 KB Output is correct
34 Correct 5 ms 9820 KB Output is correct
35 Correct 4 ms 9820 KB Output is correct
36 Correct 5 ms 9820 KB Output is correct
37 Correct 5 ms 9860 KB Output is correct
38 Correct 6 ms 9820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9664 KB Output is correct
7 Correct 4 ms 9820 KB Output is correct
8 Correct 4 ms 9852 KB Output is correct
9 Correct 4 ms 9816 KB Output is correct
10 Correct 4 ms 9820 KB Output is correct
11 Correct 4 ms 9820 KB Output is correct
12 Correct 4 ms 9820 KB Output is correct
13 Correct 4 ms 9816 KB Output is correct
14 Correct 5 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 6 ms 9820 KB Output is correct
17 Correct 4 ms 9856 KB Output is correct
18 Correct 4 ms 9820 KB Output is correct
19 Correct 80 ms 19592 KB Output is correct
20 Correct 68 ms 19536 KB Output is correct
21 Correct 66 ms 19540 KB Output is correct
22 Correct 66 ms 19628 KB Output is correct
23 Correct 89 ms 20172 KB Output is correct
24 Correct 73 ms 19332 KB Output is correct
25 Correct 60 ms 31656 KB Output is correct
26 Correct 47 ms 42576 KB Output is correct
27 Correct 112 ms 29524 KB Output is correct
28 Correct 202 ms 75092 KB Output is correct
29 Correct 215 ms 73376 KB Output is correct
30 Correct 115 ms 29524 KB Output is correct
31 Correct 123 ms 29520 KB Output is correct
32 Correct 129 ms 29664 KB Output is correct
33 Correct 136 ms 28976 KB Output is correct
34 Correct 227 ms 42120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9664 KB Output is correct
7 Correct 4 ms 9820 KB Output is correct
8 Correct 4 ms 9852 KB Output is correct
9 Correct 4 ms 9816 KB Output is correct
10 Correct 4 ms 9820 KB Output is correct
11 Correct 4 ms 9820 KB Output is correct
12 Correct 4 ms 9820 KB Output is correct
13 Correct 4 ms 9816 KB Output is correct
14 Correct 5 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 6 ms 9820 KB Output is correct
17 Correct 4 ms 9856 KB Output is correct
18 Correct 4 ms 9820 KB Output is correct
19 Correct 4 ms 9820 KB Output is correct
20 Correct 4 ms 9820 KB Output is correct
21 Correct 4 ms 9816 KB Output is correct
22 Correct 5 ms 9820 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 5 ms 9820 KB Output is correct
25 Correct 5 ms 9820 KB Output is correct
26 Correct 6 ms 9820 KB Output is correct
27 Correct 4 ms 9844 KB Output is correct
28 Correct 5 ms 9884 KB Output is correct
29 Correct 5 ms 9820 KB Output is correct
30 Correct 5 ms 9820 KB Output is correct
31 Correct 5 ms 9820 KB Output is correct
32 Correct 4 ms 9820 KB Output is correct
33 Correct 5 ms 9820 KB Output is correct
34 Correct 5 ms 9820 KB Output is correct
35 Correct 4 ms 9820 KB Output is correct
36 Correct 5 ms 9820 KB Output is correct
37 Correct 5 ms 9860 KB Output is correct
38 Correct 6 ms 9820 KB Output is correct
39 Correct 80 ms 19592 KB Output is correct
40 Correct 68 ms 19536 KB Output is correct
41 Correct 66 ms 19540 KB Output is correct
42 Correct 66 ms 19628 KB Output is correct
43 Correct 89 ms 20172 KB Output is correct
44 Correct 73 ms 19332 KB Output is correct
45 Correct 60 ms 31656 KB Output is correct
46 Correct 47 ms 42576 KB Output is correct
47 Correct 112 ms 29524 KB Output is correct
48 Correct 202 ms 75092 KB Output is correct
49 Correct 215 ms 73376 KB Output is correct
50 Correct 115 ms 29524 KB Output is correct
51 Correct 123 ms 29520 KB Output is correct
52 Correct 129 ms 29664 KB Output is correct
53 Correct 136 ms 28976 KB Output is correct
54 Correct 227 ms 42120 KB Output is correct
55 Correct 13 ms 11100 KB Output is correct
56 Correct 8 ms 10844 KB Output is correct
57 Correct 38 ms 19912 KB Output is correct
58 Correct 36 ms 18624 KB Output is correct
59 Correct 66 ms 42580 KB Output is correct
60 Correct 194 ms 73808 KB Output is correct
61 Correct 145 ms 31316 KB Output is correct
62 Correct 118 ms 29524 KB Output is correct
63 Correct 131 ms 29704 KB Output is correct
64 Correct 296 ms 37968 KB Output is correct
65 Correct 275 ms 41976 KB Output is correct
66 Correct 213 ms 69712 KB Output is correct
67 Correct 93 ms 28604 KB Output is correct
68 Correct 198 ms 40020 KB Output is correct
69 Correct 235 ms 44104 KB Output is correct
70 Correct 197 ms 38740 KB Output is correct