Submission #884249

# Submission time Handle Problem Language Result Execution time Memory
884249 2023-12-07T03:32:48 Z AlphaMale06 Race (IOI11_race) C++14
100 / 100
372 ms 86868 KB
#include<bits/stdc++.h>
#include "race.h"

using namespace std;

#define pb push_back
#define F first
#define S second

const int N = 2e5+3;
int inf=1e9;
vector<pair<int, int>> adj[N];
int d[N];
int c[N];
int x;
int ans=inf;
map<int, int> mapa[N];

void dfs(int v, int p, int dep, int cost){
    c[v]=cost;
    d[v]=dep;
    for(auto to : adj[v]){
        if(to.F!=p){
            dfs(to.F, v, dep+1, cost+to.S);
        }
    }
}

void bst(int v, int p){
    mapa[v][c[v]]=d[v];
    for(auto to : adj[v]){
        if(to.F!=p){
            bst(to.F, v);
            if(mapa[to.F].size()>mapa[v].size())mapa[v].swap(mapa[to.F]);
            for(auto it : mapa[to.F]){
                int wnt=x+2*c[v]-it.F;
                if(mapa[v].count(wnt))ans=min(ans, mapa[v][wnt]+it.S-2*d[v]);
            }
            for(auto it : mapa[to.F]){
                if(mapa[v].count(it.F))mapa[v][it.F]=min(mapa[v][it.F], it.S);
                else mapa[v][it.F]=it.S;
            }
            if(mapa[v].count(x+c[v])){
                ans=min(ans, mapa[v][x+c[v]]-d[v]);
            }
        }
    }
}

int best_path(int n, int k, int h[][2], int l[])
{
    x=k;
    for(int i=0; i< n-1; i++){
        adj[h[i][0]].pb({h[i][1], l[i]});
        adj[h[i][1]].pb({h[i][0], l[i]});
    }
    dfs(0, -1, 0, 0);
    bst(0, -1);
    if(ans==inf)return -1;
    else return ans;
}

# Verdict Execution time Memory Grader output
1 Correct 4 ms 19544 KB Output is correct
2 Correct 3 ms 19548 KB Output is correct
3 Correct 4 ms 19744 KB Output is correct
4 Correct 3 ms 19544 KB Output is correct
5 Correct 4 ms 19548 KB Output is correct
6 Correct 4 ms 19548 KB Output is correct
7 Correct 4 ms 19640 KB Output is correct
8 Correct 4 ms 19548 KB Output is correct
9 Correct 4 ms 19544 KB Output is correct
10 Correct 4 ms 19548 KB Output is correct
11 Correct 4 ms 19708 KB Output is correct
12 Correct 4 ms 19548 KB Output is correct
13 Correct 4 ms 19548 KB Output is correct
14 Correct 4 ms 19548 KB Output is correct
15 Correct 4 ms 19548 KB Output is correct
16 Correct 4 ms 19636 KB Output is correct
17 Correct 4 ms 19548 KB Output is correct
18 Correct 4 ms 19548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19544 KB Output is correct
2 Correct 3 ms 19548 KB Output is correct
3 Correct 4 ms 19744 KB Output is correct
4 Correct 3 ms 19544 KB Output is correct
5 Correct 4 ms 19548 KB Output is correct
6 Correct 4 ms 19548 KB Output is correct
7 Correct 4 ms 19640 KB Output is correct
8 Correct 4 ms 19548 KB Output is correct
9 Correct 4 ms 19544 KB Output is correct
10 Correct 4 ms 19548 KB Output is correct
11 Correct 4 ms 19708 KB Output is correct
12 Correct 4 ms 19548 KB Output is correct
13 Correct 4 ms 19548 KB Output is correct
14 Correct 4 ms 19548 KB Output is correct
15 Correct 4 ms 19548 KB Output is correct
16 Correct 4 ms 19636 KB Output is correct
17 Correct 4 ms 19548 KB Output is correct
18 Correct 4 ms 19548 KB Output is correct
19 Correct 4 ms 19544 KB Output is correct
20 Correct 4 ms 19804 KB Output is correct
21 Correct 5 ms 20060 KB Output is correct
22 Correct 5 ms 19800 KB Output is correct
23 Correct 4 ms 19804 KB Output is correct
24 Correct 4 ms 19748 KB Output is correct
25 Correct 4 ms 19804 KB Output is correct
26 Correct 5 ms 19804 KB Output is correct
27 Correct 4 ms 19804 KB Output is correct
28 Correct 5 ms 19804 KB Output is correct
29 Correct 5 ms 19804 KB Output is correct
30 Correct 5 ms 19804 KB Output is correct
31 Correct 5 ms 19804 KB Output is correct
32 Correct 4 ms 19804 KB Output is correct
33 Correct 5 ms 19804 KB Output is correct
34 Correct 5 ms 19712 KB Output is correct
35 Correct 4 ms 19804 KB Output is correct
36 Correct 5 ms 19944 KB Output is correct
37 Correct 4 ms 19804 KB Output is correct
38 Correct 5 ms 19800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19544 KB Output is correct
2 Correct 3 ms 19548 KB Output is correct
3 Correct 4 ms 19744 KB Output is correct
4 Correct 3 ms 19544 KB Output is correct
5 Correct 4 ms 19548 KB Output is correct
6 Correct 4 ms 19548 KB Output is correct
7 Correct 4 ms 19640 KB Output is correct
8 Correct 4 ms 19548 KB Output is correct
9 Correct 4 ms 19544 KB Output is correct
10 Correct 4 ms 19548 KB Output is correct
11 Correct 4 ms 19708 KB Output is correct
12 Correct 4 ms 19548 KB Output is correct
13 Correct 4 ms 19548 KB Output is correct
14 Correct 4 ms 19548 KB Output is correct
15 Correct 4 ms 19548 KB Output is correct
16 Correct 4 ms 19636 KB Output is correct
17 Correct 4 ms 19548 KB Output is correct
18 Correct 4 ms 19548 KB Output is correct
19 Correct 107 ms 38296 KB Output is correct
20 Correct 95 ms 38224 KB Output is correct
21 Correct 88 ms 37912 KB Output is correct
22 Correct 88 ms 37812 KB Output is correct
23 Correct 127 ms 47328 KB Output is correct
24 Correct 93 ms 40288 KB Output is correct
25 Correct 79 ms 39312 KB Output is correct
26 Correct 48 ms 46304 KB Output is correct
27 Correct 145 ms 45396 KB Output is correct
28 Correct 237 ms 79788 KB Output is correct
29 Correct 225 ms 78160 KB Output is correct
30 Correct 151 ms 45396 KB Output is correct
31 Correct 143 ms 45652 KB Output is correct
32 Correct 193 ms 45648 KB Output is correct
33 Correct 192 ms 49068 KB Output is correct
34 Correct 276 ms 73164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19544 KB Output is correct
2 Correct 3 ms 19548 KB Output is correct
3 Correct 4 ms 19744 KB Output is correct
4 Correct 3 ms 19544 KB Output is correct
5 Correct 4 ms 19548 KB Output is correct
6 Correct 4 ms 19548 KB Output is correct
7 Correct 4 ms 19640 KB Output is correct
8 Correct 4 ms 19548 KB Output is correct
9 Correct 4 ms 19544 KB Output is correct
10 Correct 4 ms 19548 KB Output is correct
11 Correct 4 ms 19708 KB Output is correct
12 Correct 4 ms 19548 KB Output is correct
13 Correct 4 ms 19548 KB Output is correct
14 Correct 4 ms 19548 KB Output is correct
15 Correct 4 ms 19548 KB Output is correct
16 Correct 4 ms 19636 KB Output is correct
17 Correct 4 ms 19548 KB Output is correct
18 Correct 4 ms 19548 KB Output is correct
19 Correct 4 ms 19544 KB Output is correct
20 Correct 4 ms 19804 KB Output is correct
21 Correct 5 ms 20060 KB Output is correct
22 Correct 5 ms 19800 KB Output is correct
23 Correct 4 ms 19804 KB Output is correct
24 Correct 4 ms 19748 KB Output is correct
25 Correct 4 ms 19804 KB Output is correct
26 Correct 5 ms 19804 KB Output is correct
27 Correct 4 ms 19804 KB Output is correct
28 Correct 5 ms 19804 KB Output is correct
29 Correct 5 ms 19804 KB Output is correct
30 Correct 5 ms 19804 KB Output is correct
31 Correct 5 ms 19804 KB Output is correct
32 Correct 4 ms 19804 KB Output is correct
33 Correct 5 ms 19804 KB Output is correct
34 Correct 5 ms 19712 KB Output is correct
35 Correct 4 ms 19804 KB Output is correct
36 Correct 5 ms 19944 KB Output is correct
37 Correct 4 ms 19804 KB Output is correct
38 Correct 5 ms 19800 KB Output is correct
39 Correct 107 ms 38296 KB Output is correct
40 Correct 95 ms 38224 KB Output is correct
41 Correct 88 ms 37912 KB Output is correct
42 Correct 88 ms 37812 KB Output is correct
43 Correct 127 ms 47328 KB Output is correct
44 Correct 93 ms 40288 KB Output is correct
45 Correct 79 ms 39312 KB Output is correct
46 Correct 48 ms 46304 KB Output is correct
47 Correct 145 ms 45396 KB Output is correct
48 Correct 237 ms 79788 KB Output is correct
49 Correct 225 ms 78160 KB Output is correct
50 Correct 151 ms 45396 KB Output is correct
51 Correct 143 ms 45652 KB Output is correct
52 Correct 193 ms 45648 KB Output is correct
53 Correct 192 ms 49068 KB Output is correct
54 Correct 276 ms 73164 KB Output is correct
55 Correct 14 ms 22096 KB Output is correct
56 Correct 10 ms 21068 KB Output is correct
57 Correct 53 ms 36360 KB Output is correct
58 Correct 41 ms 31220 KB Output is correct
59 Correct 71 ms 51112 KB Output is correct
60 Correct 221 ms 78768 KB Output is correct
61 Correct 174 ms 48080 KB Output is correct
62 Correct 137 ms 45396 KB Output is correct
63 Correct 199 ms 45536 KB Output is correct
64 Correct 372 ms 86868 KB Output is correct
65 Correct 349 ms 85408 KB Output is correct
66 Correct 245 ms 74692 KB Output is correct
67 Correct 133 ms 41332 KB Output is correct
68 Correct 290 ms 58256 KB Output is correct
69 Correct 309 ms 61776 KB Output is correct
70 Correct 266 ms 56792 KB Output is correct