Submission #888535

# Submission time Handle Problem Language Result Execution time Memory
888535 2023-12-17T16:33:43 Z dwuy Race (IOI11_race) C++14
100 / 100
692 ms 45416 KB
//#include "race.h"
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;

const int MX = 200005;
int n, k, ans = MX;
int numC[MX];
bitset<MX> vist;
vector<pii> G[MX];

void calChild(int u, int p){
    numC[u] = 1;
    for(pii &tmp: G[u]){
        int v, c;
        tie(v, c) = tmp;
        if(v==p || vist[v]) continue;
        calChild(v, u);
        numC[u] += numC[v];
    }
}

int Centroid(int u, int p, const int &half){
    for(pii &tmp: G[u]){
        int v = tmp.fi;
        if(v == p || vist[v]) continue;
        if(numC[v] > half) return Centroid(v, u, half);
    }
    return u;
}

int dis[MX];
int node[MX];

int getmap(map<int, int> &mp, int value){
    auto itr = mp.find(value);
    if(itr == mp.end()) return 0;
    return itr->se;
}

int calValue(int u){
    map<int, int> mp;
    int res = MX;
    mp[0] = 1;
    for(pii &tmp: G[u]){
        int v, c;
        tie(v, c) = tmp;
        if (vist[v]) continue;
        vector<int> path;
        stack<pii> Q;
        Q.push({v, u});
        node[v] = 2;
        dis[v] = c;
        while(Q.size()){
            int u, p;
            tie(u, p) = Q.top();
            Q.pop();
            path.push_back(u);
            for(pii &tmp: G[u]){
                int v, c;
                tie(v, c) = tmp;
                if(vist[v] || v == p) continue;
                Q.push({v, u});
                dis[v] = dis[u] + c;
                node[v] = node[u] + 1;
            }
        }
        for(int vt: path) if(dis[vt]<=k){
            int gm = getmap(mp, k - dis[vt]);
            if(gm) res = min(res, gm + node[vt] - 1);
        }
        for(int vt: path) if(dis[vt]<=k){
            if(mp[dis[vt]]==0) mp[dis[vt]] = node[vt];
            else mp[dis[vt]] = min(mp[dis[vt]], node[vt]);
        }
    }
    return res;
}

void dwuy_simp_nvpu(int u){
    calChild(u, 0);
    u = Centroid(u, 0, numC[u]>>1);
    ans = min(ans, calValue(u));
    vist[u] = 1;
    for(pii &tmp: G[u]){
        int v = tmp.fi;
        if(!vist[v]) dwuy_simp_nvpu(v);
    }
}

int best_path(int N, int K, int H[][2], int L[]){
    n = N;
    k = K;
    for(int i=0; i<n-1; i++){
        int u = H[i][0];
        int v = H[i][1];
        int c = L[i];
        u++, v++;
        G[u].push_back({v, c});
        G[v].push_back({u, c});
    }
    dwuy_simp_nvpu(1);
    return ans==MX? -1 : ans - 1;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 3 ms 10744 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 3 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 3 ms 10584 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10696 KB Output is correct
13 Correct 2 ms 10584 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10676 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 3 ms 10744 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 3 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 3 ms 10584 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10696 KB Output is correct
13 Correct 2 ms 10584 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10676 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10700 KB Output is correct
21 Correct 3 ms 10588 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 3 ms 10588 KB Output is correct
24 Correct 3 ms 10588 KB Output is correct
25 Correct 3 ms 10588 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 3 ms 10588 KB Output is correct
28 Correct 3 ms 10588 KB Output is correct
29 Correct 3 ms 10588 KB Output is correct
30 Correct 3 ms 10588 KB Output is correct
31 Correct 3 ms 10588 KB Output is correct
32 Correct 3 ms 10588 KB Output is correct
33 Correct 4 ms 10588 KB Output is correct
34 Correct 3 ms 10588 KB Output is correct
35 Correct 3 ms 10588 KB Output is correct
36 Correct 3 ms 10584 KB Output is correct
37 Correct 4 ms 10588 KB Output is correct
38 Correct 3 ms 10788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 3 ms 10744 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 3 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 3 ms 10584 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10696 KB Output is correct
13 Correct 2 ms 10584 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10676 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 154 ms 18256 KB Output is correct
20 Correct 180 ms 18312 KB Output is correct
21 Correct 151 ms 18296 KB Output is correct
22 Correct 153 ms 18392 KB Output is correct
23 Correct 96 ms 18508 KB Output is correct
24 Correct 99 ms 18384 KB Output is correct
25 Correct 152 ms 21920 KB Output is correct
26 Correct 105 ms 25628 KB Output is correct
27 Correct 167 ms 23136 KB Output is correct
28 Correct 281 ms 38468 KB Output is correct
29 Correct 323 ms 37408 KB Output is correct
30 Correct 170 ms 23380 KB Output is correct
31 Correct 164 ms 23124 KB Output is correct
32 Correct 174 ms 23056 KB Output is correct
33 Correct 267 ms 22820 KB Output is correct
34 Correct 228 ms 23244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10584 KB Output is correct
2 Correct 3 ms 10744 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 3 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 3 ms 10584 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10696 KB Output is correct
13 Correct 2 ms 10584 KB Output is correct
14 Correct 2 ms 10588 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10676 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10700 KB Output is correct
21 Correct 3 ms 10588 KB Output is correct
22 Correct 2 ms 10588 KB Output is correct
23 Correct 3 ms 10588 KB Output is correct
24 Correct 3 ms 10588 KB Output is correct
25 Correct 3 ms 10588 KB Output is correct
26 Correct 2 ms 10588 KB Output is correct
27 Correct 3 ms 10588 KB Output is correct
28 Correct 3 ms 10588 KB Output is correct
29 Correct 3 ms 10588 KB Output is correct
30 Correct 3 ms 10588 KB Output is correct
31 Correct 3 ms 10588 KB Output is correct
32 Correct 3 ms 10588 KB Output is correct
33 Correct 4 ms 10588 KB Output is correct
34 Correct 3 ms 10588 KB Output is correct
35 Correct 3 ms 10588 KB Output is correct
36 Correct 3 ms 10584 KB Output is correct
37 Correct 4 ms 10588 KB Output is correct
38 Correct 3 ms 10788 KB Output is correct
39 Correct 154 ms 18256 KB Output is correct
40 Correct 180 ms 18312 KB Output is correct
41 Correct 151 ms 18296 KB Output is correct
42 Correct 153 ms 18392 KB Output is correct
43 Correct 96 ms 18508 KB Output is correct
44 Correct 99 ms 18384 KB Output is correct
45 Correct 152 ms 21920 KB Output is correct
46 Correct 105 ms 25628 KB Output is correct
47 Correct 167 ms 23136 KB Output is correct
48 Correct 281 ms 38468 KB Output is correct
49 Correct 323 ms 37408 KB Output is correct
50 Correct 170 ms 23380 KB Output is correct
51 Correct 164 ms 23124 KB Output is correct
52 Correct 174 ms 23056 KB Output is correct
53 Correct 267 ms 22820 KB Output is correct
54 Correct 228 ms 23244 KB Output is correct
55 Correct 17 ms 11352 KB Output is correct
56 Correct 12 ms 11100 KB Output is correct
57 Correct 124 ms 18524 KB Output is correct
58 Correct 40 ms 17604 KB Output is correct
59 Correct 268 ms 28656 KB Output is correct
60 Correct 689 ms 45416 KB Output is correct
61 Correct 223 ms 22868 KB Output is correct
62 Correct 231 ms 22868 KB Output is correct
63 Correct 245 ms 22876 KB Output is correct
64 Correct 692 ms 27524 KB Output is correct
65 Correct 184 ms 23764 KB Output is correct
66 Correct 509 ms 34412 KB Output is correct
67 Correct 98 ms 23488 KB Output is correct
68 Correct 287 ms 26996 KB Output is correct
69 Correct 303 ms 26868 KB Output is correct
70 Correct 267 ms 26460 KB Output is correct