Submission #149230

# Submission time Handle Problem Language Result Execution time Memory
149230 2019-09-01T06:01:08 Z anonymous Race (IOI11_race) C++14
100 / 100
755 ms 97144 KB
#include<iostream>
#include<tr1/unordered_map>
#include<utility>
#include<vector>
#include "race.h"
using namespace std;
int N,ui,vi,wi;
long long K;
int big[200005],out=1<<30;
vector <pair<int,int> > adj[200005];
tr1::unordered_map<long long,int>  M[200005];
int dfs(int u, int prev, long long depth, int e) {
    big[u]=u;
    M[u][depth]=e;
    for (auto v: adj[u]) {
        if (v.first == prev) {continue;}
        int res=dfs(v.first,u,depth+v.second,e+1);
        if (M[big[u]].size()<M[res].size()) {
            swap(big[u],res);
        }
        for (auto val: M[res]) {
            if (M[big[u]].find(K+2*depth-val.first) != M[big[u]].end()) {
                out=min(out,M[big[u]][K+2*depth-val.first]+val.second-2*e);
            }
        }
        for (auto val: M[res]) {
            if (M[big[u]].find(val.first)==M[big[u]].end()) {
                M[big[u]][val.first]=val.second;
            } if (M[big[u]][val.first]>val.second) {
                M[big[u]][val.first]=val.second;
            }
        }
    }
    return(big[u]);
}

int best_path(int n, int k, int H[][2], int L[]) {
    K=k;
    for (int i=0; i<n-1; i++) {
        adj[H[i][0]].push_back({H[i][1],L[i]});
        adj[H[i][1]].push_back({H[i][0],L[i]});
    } //1 indexify
    dfs(0,-1,0,0);
    return(out<=n ? out : -1);
}
# Verdict Execution time Memory Grader output
1 Correct 45 ms 36344 KB Output is correct
2 Correct 44 ms 36344 KB Output is correct
3 Correct 45 ms 36316 KB Output is correct
4 Correct 45 ms 36360 KB Output is correct
5 Correct 45 ms 36344 KB Output is correct
6 Correct 45 ms 36316 KB Output is correct
7 Correct 45 ms 36412 KB Output is correct
8 Correct 49 ms 36512 KB Output is correct
9 Correct 46 ms 36472 KB Output is correct
10 Correct 44 ms 36344 KB Output is correct
11 Correct 45 ms 36360 KB Output is correct
12 Correct 46 ms 36344 KB Output is correct
13 Correct 46 ms 36344 KB Output is correct
14 Correct 45 ms 36412 KB Output is correct
15 Correct 46 ms 36308 KB Output is correct
16 Correct 46 ms 36420 KB Output is correct
17 Correct 45 ms 36444 KB Output is correct
18 Correct 45 ms 36300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 36344 KB Output is correct
2 Correct 44 ms 36344 KB Output is correct
3 Correct 45 ms 36316 KB Output is correct
4 Correct 45 ms 36360 KB Output is correct
5 Correct 45 ms 36344 KB Output is correct
6 Correct 45 ms 36316 KB Output is correct
7 Correct 45 ms 36412 KB Output is correct
8 Correct 49 ms 36512 KB Output is correct
9 Correct 46 ms 36472 KB Output is correct
10 Correct 44 ms 36344 KB Output is correct
11 Correct 45 ms 36360 KB Output is correct
12 Correct 46 ms 36344 KB Output is correct
13 Correct 46 ms 36344 KB Output is correct
14 Correct 45 ms 36412 KB Output is correct
15 Correct 46 ms 36308 KB Output is correct
16 Correct 46 ms 36420 KB Output is correct
17 Correct 45 ms 36444 KB Output is correct
18 Correct 45 ms 36300 KB Output is correct
19 Correct 45 ms 36364 KB Output is correct
20 Correct 46 ms 36292 KB Output is correct
21 Correct 47 ms 36472 KB Output is correct
22 Correct 49 ms 36612 KB Output is correct
23 Correct 46 ms 36600 KB Output is correct
24 Correct 46 ms 36648 KB Output is correct
25 Correct 47 ms 36472 KB Output is correct
26 Correct 47 ms 36628 KB Output is correct
27 Correct 45 ms 36472 KB Output is correct
28 Correct 46 ms 36588 KB Output is correct
29 Correct 48 ms 36576 KB Output is correct
30 Correct 47 ms 36484 KB Output is correct
31 Correct 48 ms 36600 KB Output is correct
32 Correct 48 ms 36680 KB Output is correct
33 Correct 47 ms 36728 KB Output is correct
34 Correct 47 ms 36476 KB Output is correct
35 Correct 51 ms 36600 KB Output is correct
36 Correct 45 ms 36472 KB Output is correct
37 Correct 47 ms 36592 KB Output is correct
38 Correct 45 ms 36472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 36344 KB Output is correct
2 Correct 44 ms 36344 KB Output is correct
3 Correct 45 ms 36316 KB Output is correct
4 Correct 45 ms 36360 KB Output is correct
5 Correct 45 ms 36344 KB Output is correct
6 Correct 45 ms 36316 KB Output is correct
7 Correct 45 ms 36412 KB Output is correct
8 Correct 49 ms 36512 KB Output is correct
9 Correct 46 ms 36472 KB Output is correct
10 Correct 44 ms 36344 KB Output is correct
11 Correct 45 ms 36360 KB Output is correct
12 Correct 46 ms 36344 KB Output is correct
13 Correct 46 ms 36344 KB Output is correct
14 Correct 45 ms 36412 KB Output is correct
15 Correct 46 ms 36308 KB Output is correct
16 Correct 46 ms 36420 KB Output is correct
17 Correct 45 ms 36444 KB Output is correct
18 Correct 45 ms 36300 KB Output is correct
19 Correct 221 ms 50332 KB Output is correct
20 Correct 224 ms 50360 KB Output is correct
21 Correct 220 ms 50104 KB Output is correct
22 Correct 222 ms 49884 KB Output is correct
23 Correct 270 ms 58640 KB Output is correct
24 Correct 221 ms 52184 KB Output is correct
25 Correct 190 ms 50392 KB Output is correct
26 Correct 115 ms 55160 KB Output is correct
27 Correct 310 ms 60596 KB Output is correct
28 Correct 470 ms 85180 KB Output is correct
29 Correct 525 ms 84260 KB Output is correct
30 Correct 302 ms 60652 KB Output is correct
31 Correct 307 ms 60600 KB Output is correct
32 Correct 415 ms 60836 KB Output is correct
33 Correct 361 ms 63592 KB Output is correct
34 Correct 661 ms 86096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 36344 KB Output is correct
2 Correct 44 ms 36344 KB Output is correct
3 Correct 45 ms 36316 KB Output is correct
4 Correct 45 ms 36360 KB Output is correct
5 Correct 45 ms 36344 KB Output is correct
6 Correct 45 ms 36316 KB Output is correct
7 Correct 45 ms 36412 KB Output is correct
8 Correct 49 ms 36512 KB Output is correct
9 Correct 46 ms 36472 KB Output is correct
10 Correct 44 ms 36344 KB Output is correct
11 Correct 45 ms 36360 KB Output is correct
12 Correct 46 ms 36344 KB Output is correct
13 Correct 46 ms 36344 KB Output is correct
14 Correct 45 ms 36412 KB Output is correct
15 Correct 46 ms 36308 KB Output is correct
16 Correct 46 ms 36420 KB Output is correct
17 Correct 45 ms 36444 KB Output is correct
18 Correct 45 ms 36300 KB Output is correct
19 Correct 45 ms 36364 KB Output is correct
20 Correct 46 ms 36292 KB Output is correct
21 Correct 47 ms 36472 KB Output is correct
22 Correct 49 ms 36612 KB Output is correct
23 Correct 46 ms 36600 KB Output is correct
24 Correct 46 ms 36648 KB Output is correct
25 Correct 47 ms 36472 KB Output is correct
26 Correct 47 ms 36628 KB Output is correct
27 Correct 45 ms 36472 KB Output is correct
28 Correct 46 ms 36588 KB Output is correct
29 Correct 48 ms 36576 KB Output is correct
30 Correct 47 ms 36484 KB Output is correct
31 Correct 48 ms 36600 KB Output is correct
32 Correct 48 ms 36680 KB Output is correct
33 Correct 47 ms 36728 KB Output is correct
34 Correct 47 ms 36476 KB Output is correct
35 Correct 51 ms 36600 KB Output is correct
36 Correct 45 ms 36472 KB Output is correct
37 Correct 47 ms 36592 KB Output is correct
38 Correct 45 ms 36472 KB Output is correct
39 Correct 221 ms 50332 KB Output is correct
40 Correct 224 ms 50360 KB Output is correct
41 Correct 220 ms 50104 KB Output is correct
42 Correct 222 ms 49884 KB Output is correct
43 Correct 270 ms 58640 KB Output is correct
44 Correct 221 ms 52184 KB Output is correct
45 Correct 190 ms 50392 KB Output is correct
46 Correct 115 ms 55160 KB Output is correct
47 Correct 310 ms 60596 KB Output is correct
48 Correct 470 ms 85180 KB Output is correct
49 Correct 525 ms 84260 KB Output is correct
50 Correct 302 ms 60652 KB Output is correct
51 Correct 307 ms 60600 KB Output is correct
52 Correct 415 ms 60836 KB Output is correct
53 Correct 361 ms 63592 KB Output is correct
54 Correct 661 ms 86096 KB Output is correct
55 Correct 63 ms 38520 KB Output is correct
56 Correct 57 ms 37624 KB Output is correct
57 Correct 137 ms 49712 KB Output is correct
58 Correct 102 ms 46060 KB Output is correct
59 Correct 135 ms 60640 KB Output is correct
60 Correct 441 ms 84428 KB Output is correct
61 Correct 330 ms 62968 KB Output is correct
62 Correct 300 ms 60796 KB Output is correct
63 Correct 422 ms 60860 KB Output is correct
64 Correct 730 ms 97144 KB Output is correct
65 Correct 755 ms 95880 KB Output is correct
66 Correct 497 ms 82368 KB Output is correct
67 Correct 301 ms 57196 KB Output is correct
68 Correct 552 ms 72772 KB Output is correct
69 Correct 572 ms 76440 KB Output is correct
70 Correct 653 ms 71464 KB Output is correct