Submission #944632

# Submission time Handle Problem Language Result Execution time Memory
944632 2024-03-13T02:11:18 Z beepbeepsheep Race (IOI11_race) C++17
100 / 100
385 ms 105708 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>
const ll maxn=2e5+5;
const ll inf=1e15;
const ll mod=1e9+7;

ll ans=inf;
vector<ii> adj[maxn];
ll n,k;
map<ll,ll> maps[maxn];
pair<ll,ll> solve(ll n, ll p){
    maps[n].insert({0,0});
    ll off=0;
    ll off2=0;
    ll b,c;
    for (auto u:adj[n]){
        if (u.first==p) continue;
        tie(b,c)=solve(u.first,n);
        b+=u.second;
        c++;
        map<ll,ll> &a=maps[u.first];
        if (maps[n].size()<a.size()) swap(maps[n],a),swap(off,b),swap(off2,c);
        for (auto v:a){
            auto it=maps[n].find(k-v.first-b-off);
            if (it!=maps[n].end()){
                ans=min(ans,it->second+v.second+off2+c);
            }
        }
        for (auto v:a){
            if (maps[n].find(v.first+b-off)==maps[n].end()){
                maps[n][v.first+b-off]=v.second+c-off2;
            } else{
                maps[n][v.first+b-off]=min(maps[n][v.first+b-off],v.second+c-off2);
            }
        }
    }
    return {off,off2};
}
int best_path(int N, int K, int H[][2], int L[])
{
    n=N,k=K;
    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]);
    }
    solve(0,-1);
    return (ans==inf?-1:ans);
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18008 KB Output is correct
2 Correct 4 ms 18012 KB Output is correct
3 Correct 4 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 4 ms 18012 KB Output is correct
6 Correct 5 ms 18012 KB Output is correct
7 Correct 4 ms 18012 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18012 KB Output is correct
10 Correct 4 ms 18012 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 4 ms 18012 KB Output is correct
13 Correct 4 ms 18012 KB Output is correct
14 Correct 4 ms 18012 KB Output is correct
15 Correct 4 ms 18012 KB Output is correct
16 Correct 4 ms 18012 KB Output is correct
17 Correct 4 ms 18008 KB Output is correct
18 Correct 4 ms 18012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18008 KB Output is correct
2 Correct 4 ms 18012 KB Output is correct
3 Correct 4 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 4 ms 18012 KB Output is correct
6 Correct 5 ms 18012 KB Output is correct
7 Correct 4 ms 18012 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18012 KB Output is correct
10 Correct 4 ms 18012 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 4 ms 18012 KB Output is correct
13 Correct 4 ms 18012 KB Output is correct
14 Correct 4 ms 18012 KB Output is correct
15 Correct 4 ms 18012 KB Output is correct
16 Correct 4 ms 18012 KB Output is correct
17 Correct 4 ms 18008 KB Output is correct
18 Correct 4 ms 18012 KB Output is correct
19 Correct 4 ms 18012 KB Output is correct
20 Correct 5 ms 18200 KB Output is correct
21 Correct 5 ms 18268 KB Output is correct
22 Correct 5 ms 18268 KB Output is correct
23 Correct 5 ms 18292 KB Output is correct
24 Correct 5 ms 18268 KB Output is correct
25 Correct 5 ms 18268 KB Output is correct
26 Correct 5 ms 18268 KB Output is correct
27 Correct 4 ms 18268 KB Output is correct
28 Correct 4 ms 18268 KB Output is correct
29 Correct 4 ms 18268 KB Output is correct
30 Correct 5 ms 18268 KB Output is correct
31 Correct 5 ms 18432 KB Output is correct
32 Correct 4 ms 18264 KB Output is correct
33 Correct 5 ms 18264 KB Output is correct
34 Correct 5 ms 18264 KB Output is correct
35 Correct 5 ms 18268 KB Output is correct
36 Correct 5 ms 18228 KB Output is correct
37 Correct 5 ms 18268 KB Output is correct
38 Correct 5 ms 18432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18008 KB Output is correct
2 Correct 4 ms 18012 KB Output is correct
3 Correct 4 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 4 ms 18012 KB Output is correct
6 Correct 5 ms 18012 KB Output is correct
7 Correct 4 ms 18012 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18012 KB Output is correct
10 Correct 4 ms 18012 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 4 ms 18012 KB Output is correct
13 Correct 4 ms 18012 KB Output is correct
14 Correct 4 ms 18012 KB Output is correct
15 Correct 4 ms 18012 KB Output is correct
16 Correct 4 ms 18012 KB Output is correct
17 Correct 4 ms 18008 KB Output is correct
18 Correct 4 ms 18012 KB Output is correct
19 Correct 108 ms 41176 KB Output is correct
20 Correct 92 ms 41988 KB Output is correct
21 Correct 84 ms 41552 KB Output is correct
22 Correct 104 ms 41716 KB Output is correct
23 Correct 129 ms 54644 KB Output is correct
24 Correct 108 ms 44936 KB Output is correct
25 Correct 87 ms 43904 KB Output is correct
26 Correct 50 ms 52304 KB Output is correct
27 Correct 148 ms 51792 KB Output is correct
28 Correct 262 ms 97104 KB Output is correct
29 Correct 261 ms 95316 KB Output is correct
30 Correct 151 ms 52336 KB Output is correct
31 Correct 153 ms 52564 KB Output is correct
32 Correct 186 ms 52308 KB Output is correct
33 Correct 188 ms 57400 KB Output is correct
34 Correct 268 ms 89956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 18008 KB Output is correct
2 Correct 4 ms 18012 KB Output is correct
3 Correct 4 ms 18012 KB Output is correct
4 Correct 4 ms 18012 KB Output is correct
5 Correct 4 ms 18012 KB Output is correct
6 Correct 5 ms 18012 KB Output is correct
7 Correct 4 ms 18012 KB Output is correct
8 Correct 4 ms 18012 KB Output is correct
9 Correct 4 ms 18012 KB Output is correct
10 Correct 4 ms 18012 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 4 ms 18012 KB Output is correct
13 Correct 4 ms 18012 KB Output is correct
14 Correct 4 ms 18012 KB Output is correct
15 Correct 4 ms 18012 KB Output is correct
16 Correct 4 ms 18012 KB Output is correct
17 Correct 4 ms 18008 KB Output is correct
18 Correct 4 ms 18012 KB Output is correct
19 Correct 4 ms 18012 KB Output is correct
20 Correct 5 ms 18200 KB Output is correct
21 Correct 5 ms 18268 KB Output is correct
22 Correct 5 ms 18268 KB Output is correct
23 Correct 5 ms 18292 KB Output is correct
24 Correct 5 ms 18268 KB Output is correct
25 Correct 5 ms 18268 KB Output is correct
26 Correct 5 ms 18268 KB Output is correct
27 Correct 4 ms 18268 KB Output is correct
28 Correct 4 ms 18268 KB Output is correct
29 Correct 4 ms 18268 KB Output is correct
30 Correct 5 ms 18268 KB Output is correct
31 Correct 5 ms 18432 KB Output is correct
32 Correct 4 ms 18264 KB Output is correct
33 Correct 5 ms 18264 KB Output is correct
34 Correct 5 ms 18264 KB Output is correct
35 Correct 5 ms 18268 KB Output is correct
36 Correct 5 ms 18228 KB Output is correct
37 Correct 5 ms 18268 KB Output is correct
38 Correct 5 ms 18432 KB Output is correct
39 Correct 108 ms 41176 KB Output is correct
40 Correct 92 ms 41988 KB Output is correct
41 Correct 84 ms 41552 KB Output is correct
42 Correct 104 ms 41716 KB Output is correct
43 Correct 129 ms 54644 KB Output is correct
44 Correct 108 ms 44936 KB Output is correct
45 Correct 87 ms 43904 KB Output is correct
46 Correct 50 ms 52304 KB Output is correct
47 Correct 148 ms 51792 KB Output is correct
48 Correct 262 ms 97104 KB Output is correct
49 Correct 261 ms 95316 KB Output is correct
50 Correct 151 ms 52336 KB Output is correct
51 Correct 153 ms 52564 KB Output is correct
52 Correct 186 ms 52308 KB Output is correct
53 Correct 188 ms 57400 KB Output is correct
54 Correct 268 ms 89956 KB Output is correct
55 Correct 15 ms 21328 KB Output is correct
56 Correct 10 ms 20000 KB Output is correct
57 Correct 56 ms 38692 KB Output is correct
58 Correct 41 ms 32196 KB Output is correct
59 Correct 81 ms 58960 KB Output is correct
60 Correct 244 ms 95764 KB Output is correct
61 Correct 179 ms 54872 KB Output is correct
62 Correct 140 ms 52304 KB Output is correct
63 Correct 194 ms 52312 KB Output is correct
64 Correct 385 ms 105708 KB Output is correct
65 Correct 365 ms 105412 KB Output is correct
66 Correct 248 ms 88508 KB Output is correct
67 Correct 138 ms 46004 KB Output is correct
68 Correct 288 ms 68336 KB Output is correct
69 Correct 333 ms 70952 KB Output is correct
70 Correct 277 ms 66640 KB Output is correct