Submission #1067061

# Submission time Handle Problem Language Result Execution time Memory
1067061 2024-08-20T10:30:17 Z Thunnus Race (IOI11_race) C++17
100 / 100
371 ms 102996 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);
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9824 KB Output is correct
3 Correct 5 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 9772 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9848 KB Output is correct
11 Correct 5 ms 9820 KB Output is correct
12 Correct 4 ms 9820 KB Output is correct
13 Correct 4 ms 9820 KB Output is correct
14 Correct 4 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 4 ms 9820 KB Output is correct
17 Correct 4 ms 9820 KB Output is correct
18 Correct 4 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9824 KB Output is correct
3 Correct 5 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 9772 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9848 KB Output is correct
11 Correct 5 ms 9820 KB Output is correct
12 Correct 4 ms 9820 KB Output is correct
13 Correct 4 ms 9820 KB Output is correct
14 Correct 4 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 4 ms 9820 KB Output is correct
17 Correct 4 ms 9820 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 10076 KB Output is correct
22 Correct 6 ms 10076 KB Output is correct
23 Correct 6 ms 10076 KB Output is correct
24 Correct 5 ms 10332 KB Output is correct
25 Correct 5 ms 10076 KB Output is correct
26 Correct 5 ms 10076 KB Output is correct
27 Correct 4 ms 9864 KB Output is correct
28 Correct 5 ms 10076 KB Output is correct
29 Correct 5 ms 10076 KB Output is correct
30 Correct 5 ms 10076 KB Output is correct
31 Correct 6 ms 10076 KB Output is correct
32 Correct 5 ms 10076 KB Output is correct
33 Correct 5 ms 10076 KB Output is correct
34 Correct 5 ms 10076 KB Output is correct
35 Correct 4 ms 10076 KB Output is correct
36 Correct 5 ms 10072 KB Output is correct
37 Correct 5 ms 10076 KB Output is correct
38 Correct 5 ms 10076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9824 KB Output is correct
3 Correct 5 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 9772 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9848 KB Output is correct
11 Correct 5 ms 9820 KB Output is correct
12 Correct 4 ms 9820 KB Output is correct
13 Correct 4 ms 9820 KB Output is correct
14 Correct 4 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 4 ms 9820 KB Output is correct
17 Correct 4 ms 9820 KB Output is correct
18 Correct 4 ms 9820 KB Output is correct
19 Correct 85 ms 35044 KB Output is correct
20 Correct 90 ms 35068 KB Output is correct
21 Correct 93 ms 34812 KB Output is correct
22 Correct 99 ms 34344 KB Output is correct
23 Correct 126 ms 47144 KB Output is correct
24 Correct 95 ms 37128 KB Output is correct
25 Correct 73 ms 35784 KB Output is correct
26 Correct 45 ms 44112 KB Output is correct
27 Correct 124 ms 48452 KB Output is correct
28 Correct 221 ms 90388 KB Output is correct
29 Correct 219 ms 88656 KB Output is correct
30 Correct 136 ms 48464 KB Output is correct
31 Correct 131 ms 48464 KB Output is correct
32 Correct 178 ms 48496 KB Output is correct
33 Correct 177 ms 53584 KB Output is correct
34 Correct 280 ms 85592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9824 KB Output is correct
3 Correct 5 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 9772 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9848 KB Output is correct
11 Correct 5 ms 9820 KB Output is correct
12 Correct 4 ms 9820 KB Output is correct
13 Correct 4 ms 9820 KB Output is correct
14 Correct 4 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 4 ms 9820 KB Output is correct
17 Correct 4 ms 9820 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 10076 KB Output is correct
22 Correct 6 ms 10076 KB Output is correct
23 Correct 6 ms 10076 KB Output is correct
24 Correct 5 ms 10332 KB Output is correct
25 Correct 5 ms 10076 KB Output is correct
26 Correct 5 ms 10076 KB Output is correct
27 Correct 4 ms 9864 KB Output is correct
28 Correct 5 ms 10076 KB Output is correct
29 Correct 5 ms 10076 KB Output is correct
30 Correct 5 ms 10076 KB Output is correct
31 Correct 6 ms 10076 KB Output is correct
32 Correct 5 ms 10076 KB Output is correct
33 Correct 5 ms 10076 KB Output is correct
34 Correct 5 ms 10076 KB Output is correct
35 Correct 4 ms 10076 KB Output is correct
36 Correct 5 ms 10072 KB Output is correct
37 Correct 5 ms 10076 KB Output is correct
38 Correct 5 ms 10076 KB Output is correct
39 Correct 85 ms 35044 KB Output is correct
40 Correct 90 ms 35068 KB Output is correct
41 Correct 93 ms 34812 KB Output is correct
42 Correct 99 ms 34344 KB Output is correct
43 Correct 126 ms 47144 KB Output is correct
44 Correct 95 ms 37128 KB Output is correct
45 Correct 73 ms 35784 KB Output is correct
46 Correct 45 ms 44112 KB Output is correct
47 Correct 124 ms 48452 KB Output is correct
48 Correct 221 ms 90388 KB Output is correct
49 Correct 219 ms 88656 KB Output is correct
50 Correct 136 ms 48464 KB Output is correct
51 Correct 131 ms 48464 KB Output is correct
52 Correct 178 ms 48496 KB Output is correct
53 Correct 177 ms 53584 KB Output is correct
54 Correct 280 ms 85592 KB Output is correct
55 Correct 14 ms 13148 KB Output is correct
56 Correct 9 ms 12080 KB Output is correct
57 Correct 51 ms 32592 KB Output is correct
58 Correct 39 ms 24868 KB Output is correct
59 Correct 76 ms 50260 KB Output is correct
60 Correct 215 ms 89168 KB Output is correct
61 Correct 162 ms 51796 KB Output is correct
62 Correct 136 ms 48208 KB Output is correct
63 Correct 153 ms 48464 KB Output is correct
64 Correct 371 ms 102996 KB Output is correct
65 Correct 371 ms 100944 KB Output is correct
66 Correct 235 ms 84304 KB Output is correct
67 Correct 116 ms 41148 KB Output is correct
68 Correct 258 ms 64336 KB Output is correct
69 Correct 269 ms 69128 KB Output is correct
70 Correct 245 ms 62032 KB Output is correct