Submission #320087

# Submission time Handle Problem Language Result Execution time Memory
320087 2020-11-07T13:44:50 Z neki Race (IOI11_race) C++14
100 / 100
656 ms 42568 KB
#include "race.h"
#include <bits/stdc++.h>
#define loop(i, a, b) for(long long i=a;i<b;i++)
#define pool(i, a, b) for(long long i=a-1;i>=b;i--)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define pb(a) pop_back(a)
#define sc scanf
#define vc vector
#define pa pair<ll, ll>
#define ll int
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 201000
#define pa pair<ll, ll>
#define ld long double 
#define intmax INT_MAX/2
vc<pa> edg[mn]; 
ll n, k, vis[mn], ans=intmax, dp[1000100], sz[mn];

ll fnd(ll st){
    function<void (ll, ll)> psa=[&](ll u, ll p){
        sz[u]=1;
        fore(v, edg[u]) if(!vis[v.fi] and v.fi!=p) psa(v.fi, u), sz[u]+=sz[v.fi];
    };
    psa(st, -1);
    ll nsiz=sz[st];
    function<ll (ll, ll)> dfs=[&](ll u, ll p){
        fore(v, edg[u]) if(!vis[v.fi] and v.fi!=p and sz[v.fi]>nsiz/2) return dfs(v.fi, u);
        return u;
    };
    return dfs(st, -1);
}

vc<pa> cur, al;
void getd(ll u, ll p, ll dist, ll le){
    cur.ps(make_pair(dist, le));
    al.ps(make_pair(dist, le));
    fore(v, edg[u]) if(!vis[v.fi] and v.fi!=p) getd(v.fi, u, dist+v.se, le+1);
}

void dec(ll st){
    ll c=fnd(st);
    dp[0]=0;
    al.clear();
    fore(v, edg[c]) if(!vis[v.fi]){
        cur.clear();
        getd(v.fi, c, v.se, 1);
        
        fore(d, cur) if(0<=k-d.fi)ans=min(ans, dp[k-d.fi]+d.se);
        fore(d, cur) if(d.fi<=k)dp[d.fi]=min(dp[d.fi], d.se);

    }
    fore(d, al) if(d.fi<=k)dp[d.fi]=intmax;
    
    vis[c]=1;
    fore(v, edg[c]) if(!vis[v.fi]) dec(v.fi);
}
ll best_path(ll N, ll K, ll h[][2], ll l[]){
    n=N, k=K;
    loop(i, 0, k+1) dp[i]=intmax;
    dp[0]=0;
    loop(i, 0, n-1){
        edg[h[i][0]].ps(make_pair(h[i][1], l[i]));
        edg[h[i][1]].ps(make_pair(h[i][0], l[i]));
    }
    dec(0);
    return (ans>n+539)? -1:ans;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 3 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5248 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5248 KB Output is correct
9 Correct 5 ms 5176 KB Output is correct
10 Correct 3 ms 5100 KB Output is correct
11 Correct 5 ms 5100 KB Output is correct
12 Correct 4 ms 5228 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 5 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 4 ms 5100 KB Output is correct
17 Correct 4 ms 5044 KB Output is correct
18 Correct 3 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 3 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5248 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5248 KB Output is correct
9 Correct 5 ms 5176 KB Output is correct
10 Correct 3 ms 5100 KB Output is correct
11 Correct 5 ms 5100 KB Output is correct
12 Correct 4 ms 5228 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 5 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 4 ms 5100 KB Output is correct
17 Correct 4 ms 5044 KB Output is correct
18 Correct 3 ms 5100 KB Output is correct
19 Correct 5 ms 5100 KB Output is correct
20 Correct 4 ms 5100 KB Output is correct
21 Correct 4 ms 5100 KB Output is correct
22 Correct 7 ms 8684 KB Output is correct
23 Correct 6 ms 8172 KB Output is correct
24 Correct 7 ms 8556 KB Output is correct
25 Correct 7 ms 8428 KB Output is correct
26 Correct 5 ms 6508 KB Output is correct
27 Correct 6 ms 8300 KB Output is correct
28 Correct 5 ms 5996 KB Output is correct
29 Correct 5 ms 6380 KB Output is correct
30 Correct 7 ms 6636 KB Output is correct
31 Correct 6 ms 7660 KB Output is correct
32 Correct 6 ms 8064 KB Output is correct
33 Correct 7 ms 8300 KB Output is correct
34 Correct 6 ms 7680 KB Output is correct
35 Correct 6 ms 8300 KB Output is correct
36 Correct 7 ms 8812 KB Output is correct
37 Correct 6 ms 8300 KB Output is correct
38 Correct 6 ms 7148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 3 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5248 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5248 KB Output is correct
9 Correct 5 ms 5176 KB Output is correct
10 Correct 3 ms 5100 KB Output is correct
11 Correct 5 ms 5100 KB Output is correct
12 Correct 4 ms 5228 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 5 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 4 ms 5100 KB Output is correct
17 Correct 4 ms 5044 KB Output is correct
18 Correct 3 ms 5100 KB Output is correct
19 Correct 212 ms 12168 KB Output is correct
20 Correct 193 ms 13276 KB Output is correct
21 Correct 192 ms 13520 KB Output is correct
22 Correct 161 ms 13472 KB Output is correct
23 Correct 143 ms 13652 KB Output is correct
24 Correct 92 ms 13400 KB Output is correct
25 Correct 185 ms 17876 KB Output is correct
26 Correct 137 ms 22436 KB Output is correct
27 Correct 247 ms 21076 KB Output is correct
28 Correct 541 ms 39660 KB Output is correct
29 Correct 521 ms 38216 KB Output is correct
30 Correct 246 ms 21224 KB Output is correct
31 Correct 246 ms 21200 KB Output is correct
32 Correct 334 ms 21224 KB Output is correct
33 Correct 370 ms 20728 KB Output is correct
34 Correct 366 ms 21620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 3 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5248 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5248 KB Output is correct
9 Correct 5 ms 5176 KB Output is correct
10 Correct 3 ms 5100 KB Output is correct
11 Correct 5 ms 5100 KB Output is correct
12 Correct 4 ms 5228 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 5 ms 5100 KB Output is correct
15 Correct 4 ms 5100 KB Output is correct
16 Correct 4 ms 5100 KB Output is correct
17 Correct 4 ms 5044 KB Output is correct
18 Correct 3 ms 5100 KB Output is correct
19 Correct 5 ms 5100 KB Output is correct
20 Correct 4 ms 5100 KB Output is correct
21 Correct 4 ms 5100 KB Output is correct
22 Correct 7 ms 8684 KB Output is correct
23 Correct 6 ms 8172 KB Output is correct
24 Correct 7 ms 8556 KB Output is correct
25 Correct 7 ms 8428 KB Output is correct
26 Correct 5 ms 6508 KB Output is correct
27 Correct 6 ms 8300 KB Output is correct
28 Correct 5 ms 5996 KB Output is correct
29 Correct 5 ms 6380 KB Output is correct
30 Correct 7 ms 6636 KB Output is correct
31 Correct 6 ms 7660 KB Output is correct
32 Correct 6 ms 8064 KB Output is correct
33 Correct 7 ms 8300 KB Output is correct
34 Correct 6 ms 7680 KB Output is correct
35 Correct 6 ms 8300 KB Output is correct
36 Correct 7 ms 8812 KB Output is correct
37 Correct 6 ms 8300 KB Output is correct
38 Correct 6 ms 7148 KB Output is correct
39 Correct 212 ms 12168 KB Output is correct
40 Correct 193 ms 13276 KB Output is correct
41 Correct 192 ms 13520 KB Output is correct
42 Correct 161 ms 13472 KB Output is correct
43 Correct 143 ms 13652 KB Output is correct
44 Correct 92 ms 13400 KB Output is correct
45 Correct 185 ms 17876 KB Output is correct
46 Correct 137 ms 22436 KB Output is correct
47 Correct 247 ms 21076 KB Output is correct
48 Correct 541 ms 39660 KB Output is correct
49 Correct 521 ms 38216 KB Output is correct
50 Correct 246 ms 21224 KB Output is correct
51 Correct 246 ms 21200 KB Output is correct
52 Correct 334 ms 21224 KB Output is correct
53 Correct 370 ms 20728 KB Output is correct
54 Correct 366 ms 21620 KB Output is correct
55 Correct 13 ms 6124 KB Output is correct
56 Correct 13 ms 5996 KB Output is correct
57 Correct 109 ms 13696 KB Output is correct
58 Correct 46 ms 13144 KB Output is correct
59 Correct 150 ms 22996 KB Output is correct
60 Correct 580 ms 42568 KB Output is correct
61 Correct 260 ms 21332 KB Output is correct
62 Correct 255 ms 25120 KB Output is correct
63 Correct 342 ms 25316 KB Output is correct
64 Correct 656 ms 24432 KB Output is correct
65 Correct 452 ms 22852 KB Output is correct
66 Correct 592 ms 39364 KB Output is correct
67 Correct 151 ms 26320 KB Output is correct
68 Correct 359 ms 26556 KB Output is correct
69 Correct 349 ms 26828 KB Output is correct
70 Correct 328 ms 25908 KB Output is correct