Submission #305039

# Submission time Handle Problem Language Result Execution time Memory
305039 2020-09-22T12:44:16 Z vipghn2003 Race (IOI11_race) C++14
100 / 100
567 ms 83192 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;

const int N=2e5+5;
int res,k;
map<int,int>mp[N];
vector<pii>adj[N];

void dfs(int u,int p=-1,int h=0,int w=0)
{
    mp[u][w]=h;
    int tmp=u;
    for(auto&to:adj[u])
    {
        int v=to.fi;
        if(v==p) continue;
        dfs(v,tmp,h+1,w+to.se);
        if(mp[u].size()<mp[v].size()) swap(mp[u],mp[v]);
        for(auto&x:mp[v])
        {
            if(mp[u].count(k+2*w-x.fi))
            {
                res=min(res,x.se+mp[u][k+2*w-x.fi]-2*h);
            }
        }
        for(auto&x:mp[v])
        {
            if(!mp[u].count(x.fi)||mp[u][x.fi]>x.se) mp[u][x.fi]=x.se;
        }
    }
}


int best_path(int n,int nk,int h[][2],int l[])
{
    k=nk;
    for(int i=0;i<n-1;i++)
    {
        adj[h[i][0]].push_back(make_pair(h[i][1],l[i]));
        adj[h[i][1]].push_back(make_pair(h[i][0],l[i]));
    }
    res=1e9;
    dfs(0);
    if(res==1e9) res=-1;
    return res;
}
/*
int main()
{
    int n,k;
    cin>>n>>k;
    int h[n][2],l[n];
    for(int i=0;i<n-1;i++) cin>>h[i][0]>>h[i][1];
    for(int i=0;i<n-1;i++) cin>>l[i];
    cout<<best_path(n,k,h,l);
}

4 3
0 1
1 2
1 3
1 2 4
*/
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 10 ms 14464 KB Output is correct
3 Correct 10 ms 14464 KB Output is correct
4 Correct 10 ms 14464 KB Output is correct
5 Correct 10 ms 14504 KB Output is correct
6 Correct 10 ms 14464 KB Output is correct
7 Correct 10 ms 14464 KB Output is correct
8 Correct 10 ms 14592 KB Output is correct
9 Correct 10 ms 14464 KB Output is correct
10 Correct 10 ms 14464 KB Output is correct
11 Correct 10 ms 14464 KB Output is correct
12 Correct 10 ms 14464 KB Output is correct
13 Correct 10 ms 14464 KB Output is correct
14 Correct 11 ms 14464 KB Output is correct
15 Correct 10 ms 14464 KB Output is correct
16 Correct 10 ms 14464 KB Output is correct
17 Correct 10 ms 14464 KB Output is correct
18 Correct 10 ms 14464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 10 ms 14464 KB Output is correct
3 Correct 10 ms 14464 KB Output is correct
4 Correct 10 ms 14464 KB Output is correct
5 Correct 10 ms 14504 KB Output is correct
6 Correct 10 ms 14464 KB Output is correct
7 Correct 10 ms 14464 KB Output is correct
8 Correct 10 ms 14592 KB Output is correct
9 Correct 10 ms 14464 KB Output is correct
10 Correct 10 ms 14464 KB Output is correct
11 Correct 10 ms 14464 KB Output is correct
12 Correct 10 ms 14464 KB Output is correct
13 Correct 10 ms 14464 KB Output is correct
14 Correct 11 ms 14464 KB Output is correct
15 Correct 10 ms 14464 KB Output is correct
16 Correct 10 ms 14464 KB Output is correct
17 Correct 10 ms 14464 KB Output is correct
18 Correct 10 ms 14464 KB Output is correct
19 Correct 10 ms 14464 KB Output is correct
20 Correct 10 ms 14464 KB Output is correct
21 Correct 11 ms 14592 KB Output is correct
22 Correct 12 ms 14720 KB Output is correct
23 Correct 12 ms 14720 KB Output is correct
24 Correct 11 ms 14720 KB Output is correct
25 Correct 11 ms 14592 KB Output is correct
26 Correct 11 ms 14720 KB Output is correct
27 Correct 11 ms 14592 KB Output is correct
28 Correct 11 ms 14592 KB Output is correct
29 Correct 12 ms 14592 KB Output is correct
30 Correct 11 ms 14592 KB Output is correct
31 Correct 11 ms 14720 KB Output is correct
32 Correct 11 ms 14592 KB Output is correct
33 Correct 11 ms 14720 KB Output is correct
34 Correct 11 ms 14592 KB Output is correct
35 Correct 11 ms 14592 KB Output is correct
36 Correct 11 ms 14592 KB Output is correct
37 Correct 11 ms 14592 KB Output is correct
38 Correct 11 ms 14592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 10 ms 14464 KB Output is correct
3 Correct 10 ms 14464 KB Output is correct
4 Correct 10 ms 14464 KB Output is correct
5 Correct 10 ms 14504 KB Output is correct
6 Correct 10 ms 14464 KB Output is correct
7 Correct 10 ms 14464 KB Output is correct
8 Correct 10 ms 14592 KB Output is correct
9 Correct 10 ms 14464 KB Output is correct
10 Correct 10 ms 14464 KB Output is correct
11 Correct 10 ms 14464 KB Output is correct
12 Correct 10 ms 14464 KB Output is correct
13 Correct 10 ms 14464 KB Output is correct
14 Correct 11 ms 14464 KB Output is correct
15 Correct 10 ms 14464 KB Output is correct
16 Correct 10 ms 14464 KB Output is correct
17 Correct 10 ms 14464 KB Output is correct
18 Correct 10 ms 14464 KB Output is correct
19 Correct 164 ms 32328 KB Output is correct
20 Correct 156 ms 32376 KB Output is correct
21 Correct 158 ms 32248 KB Output is correct
22 Correct 168 ms 31864 KB Output is correct
23 Correct 201 ms 41592 KB Output is correct
24 Correct 160 ms 34424 KB Output is correct
25 Correct 128 ms 33528 KB Output is correct
26 Correct 81 ms 40568 KB Output is correct
27 Correct 253 ms 41592 KB Output is correct
28 Correct 341 ms 76152 KB Output is correct
29 Correct 345 ms 74616 KB Output is correct
30 Correct 265 ms 41616 KB Output is correct
31 Correct 249 ms 41592 KB Output is correct
32 Correct 320 ms 41768 KB Output is correct
33 Correct 299 ms 45048 KB Output is correct
34 Correct 428 ms 69928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 10 ms 14464 KB Output is correct
3 Correct 10 ms 14464 KB Output is correct
4 Correct 10 ms 14464 KB Output is correct
5 Correct 10 ms 14504 KB Output is correct
6 Correct 10 ms 14464 KB Output is correct
7 Correct 10 ms 14464 KB Output is correct
8 Correct 10 ms 14592 KB Output is correct
9 Correct 10 ms 14464 KB Output is correct
10 Correct 10 ms 14464 KB Output is correct
11 Correct 10 ms 14464 KB Output is correct
12 Correct 10 ms 14464 KB Output is correct
13 Correct 10 ms 14464 KB Output is correct
14 Correct 11 ms 14464 KB Output is correct
15 Correct 10 ms 14464 KB Output is correct
16 Correct 10 ms 14464 KB Output is correct
17 Correct 10 ms 14464 KB Output is correct
18 Correct 10 ms 14464 KB Output is correct
19 Correct 10 ms 14464 KB Output is correct
20 Correct 10 ms 14464 KB Output is correct
21 Correct 11 ms 14592 KB Output is correct
22 Correct 12 ms 14720 KB Output is correct
23 Correct 12 ms 14720 KB Output is correct
24 Correct 11 ms 14720 KB Output is correct
25 Correct 11 ms 14592 KB Output is correct
26 Correct 11 ms 14720 KB Output is correct
27 Correct 11 ms 14592 KB Output is correct
28 Correct 11 ms 14592 KB Output is correct
29 Correct 12 ms 14592 KB Output is correct
30 Correct 11 ms 14592 KB Output is correct
31 Correct 11 ms 14720 KB Output is correct
32 Correct 11 ms 14592 KB Output is correct
33 Correct 11 ms 14720 KB Output is correct
34 Correct 11 ms 14592 KB Output is correct
35 Correct 11 ms 14592 KB Output is correct
36 Correct 11 ms 14592 KB Output is correct
37 Correct 11 ms 14592 KB Output is correct
38 Correct 11 ms 14592 KB Output is correct
39 Correct 164 ms 32328 KB Output is correct
40 Correct 156 ms 32376 KB Output is correct
41 Correct 158 ms 32248 KB Output is correct
42 Correct 168 ms 31864 KB Output is correct
43 Correct 201 ms 41592 KB Output is correct
44 Correct 160 ms 34424 KB Output is correct
45 Correct 128 ms 33528 KB Output is correct
46 Correct 81 ms 40568 KB Output is correct
47 Correct 253 ms 41592 KB Output is correct
48 Correct 341 ms 76152 KB Output is correct
49 Correct 345 ms 74616 KB Output is correct
50 Correct 265 ms 41616 KB Output is correct
51 Correct 249 ms 41592 KB Output is correct
52 Correct 320 ms 41768 KB Output is correct
53 Correct 299 ms 45048 KB Output is correct
54 Correct 428 ms 69928 KB Output is correct
55 Correct 28 ms 16888 KB Output is correct
56 Correct 19 ms 16000 KB Output is correct
57 Correct 95 ms 30412 KB Output is correct
58 Correct 73 ms 25324 KB Output is correct
59 Correct 108 ms 45048 KB Output is correct
60 Correct 329 ms 74872 KB Output is correct
61 Correct 313 ms 44280 KB Output is correct
62 Correct 262 ms 41592 KB Output is correct
63 Correct 317 ms 41724 KB Output is correct
64 Correct 567 ms 83192 KB Output is correct
65 Correct 566 ms 81848 KB Output is correct
66 Correct 359 ms 71032 KB Output is correct
67 Correct 226 ms 37604 KB Output is correct
68 Correct 461 ms 54524 KB Output is correct
69 Correct 468 ms 58360 KB Output is correct
70 Correct 407 ms 52984 KB Output is correct