Submission #109675

# Submission time Handle Problem Language Result Execution time Memory
109675 2019-05-07T11:16:02 Z someone_aa Race (IOI11_race) C++17
21 / 100
242 ms 4856 KB
#include <bits/stdc++.h>
#include "race.h"
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 1100;
const int maxk = 1100000;

vector<pair<int,int> > g[maxn];
bool deleted[maxn];
int sbtsum[maxn], parent[maxn];
int n, k;

class path {
public:
    int node, sum, cnt;
};

vector<path> curr_paths;
void find_paths(int node, int p, int sum, int cnt) {
    curr_paths.pb({node, sum, cnt});
    for(auto i:g[node]) {
        if(deleted[i.first] || i.first == p) continue;
        find_paths(i.first, node, sum+i.second, cnt+1);
    }
}

int min_cnt[maxk];
int result;

void solve(int node) {
    memset(min_cnt,0,sizeof(min_cnt));
    for(auto i:g[node]) {
        if(deleted[i.first]) continue;
        curr_paths.clear();
        find_paths(i.first, -1, 0, 0);

        for(auto j:curr_paths) {
            int curr = j.sum + i.second;

            if(curr > k) continue;
            else if(curr == k) result = min(result, j.cnt+1);
            else {
                int diff = k - curr;
                if(min_cnt[diff] != 0) result = min(result, min_cnt[diff] + j.cnt + 1);
            }
        }

        for(auto j:curr_paths) {
            int curr = j.sum + i.second;

            if(curr > k) continue;

            int newval = j.cnt + 1;
            if(min_cnt[curr] == 0) min_cnt[curr] = newval;
            else min_cnt[curr] = min(min_cnt[curr], newval);
        }
    }
}

void dfs0(int node, int p) {
    sbtsum[node] = 1;
    parent[node] = p;
    for(auto i:g[node]) {
        if(deleted[i.first] || i.first == p) continue;
        dfs0(i.first, node);
        sbtsum[node] += sbtsum[i.first];
    }
}

void decompose(int node) {
    dfs0(node, -1);

    int best_size = sbtsum[node];
    int centroid = node;

    queue<int>q;
    q.push(node);

    while(!q.empty()) {
        int curr = q.front();
        q.pop();

        int curr_size = sbtsum[node] - sbtsum[curr];
        for(auto i:g[curr]) {
            if(deleted[i.first] || parent[i.first] != curr) continue;
            curr_size = max(curr_size, sbtsum[i.first]);
            q.push(i.first);
        }

        if(curr_size < best_size) {
            best_size = curr_size;
            centroid = curr;
        }
    }

    deleted[centroid] = true;
    solve(centroid);
    for(auto i:g[centroid]) {
        if(deleted[i.first]) continue;
        decompose(i.first);
    }
}

int best_path(int N, int K, int H[][2], int L[]) {
    n = N; k = K;
    result = INT_MAX;
    for(int i=0;i<N-1;i++) {
        int a = H[i][0];
        int b = H[i][1];
        int c = L[i];

        g[a].pb(mp(b, c));
        g[b].pb(mp(a, c));
    }

    decompose(0);
    if(result == INT_MAX) return -1;
    return result;
}
# Verdict Execution time Memory Grader output
1 Correct 29 ms 4608 KB Output is correct
2 Correct 27 ms 4608 KB Output is correct
3 Correct 30 ms 4736 KB Output is correct
4 Correct 29 ms 4736 KB Output is correct
5 Correct 26 ms 4608 KB Output is correct
6 Correct 25 ms 4608 KB Output is correct
7 Correct 31 ms 4608 KB Output is correct
8 Correct 29 ms 4608 KB Output is correct
9 Correct 27 ms 4764 KB Output is correct
10 Correct 25 ms 4608 KB Output is correct
11 Correct 26 ms 4728 KB Output is correct
12 Correct 29 ms 4608 KB Output is correct
13 Correct 32 ms 4736 KB Output is correct
14 Correct 28 ms 4736 KB Output is correct
15 Correct 28 ms 4736 KB Output is correct
16 Correct 31 ms 4736 KB Output is correct
17 Correct 29 ms 4608 KB Output is correct
18 Correct 31 ms 4856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 4608 KB Output is correct
2 Correct 27 ms 4608 KB Output is correct
3 Correct 30 ms 4736 KB Output is correct
4 Correct 29 ms 4736 KB Output is correct
5 Correct 26 ms 4608 KB Output is correct
6 Correct 25 ms 4608 KB Output is correct
7 Correct 31 ms 4608 KB Output is correct
8 Correct 29 ms 4608 KB Output is correct
9 Correct 27 ms 4764 KB Output is correct
10 Correct 25 ms 4608 KB Output is correct
11 Correct 26 ms 4728 KB Output is correct
12 Correct 29 ms 4608 KB Output is correct
13 Correct 32 ms 4736 KB Output is correct
14 Correct 28 ms 4736 KB Output is correct
15 Correct 28 ms 4736 KB Output is correct
16 Correct 31 ms 4736 KB Output is correct
17 Correct 29 ms 4608 KB Output is correct
18 Correct 31 ms 4856 KB Output is correct
19 Correct 8 ms 4736 KB Output is correct
20 Correct 27 ms 4736 KB Output is correct
21 Correct 224 ms 4856 KB Output is correct
22 Correct 227 ms 4768 KB Output is correct
23 Correct 203 ms 4736 KB Output is correct
24 Correct 219 ms 4856 KB Output is correct
25 Correct 238 ms 4772 KB Output is correct
26 Correct 242 ms 4736 KB Output is correct
27 Correct 240 ms 4736 KB Output is correct
28 Correct 230 ms 4856 KB Output is correct
29 Correct 209 ms 4736 KB Output is correct
30 Correct 203 ms 4736 KB Output is correct
31 Correct 216 ms 4856 KB Output is correct
32 Correct 218 ms 4736 KB Output is correct
33 Correct 220 ms 4736 KB Output is correct
34 Correct 230 ms 4784 KB Output is correct
35 Correct 193 ms 4736 KB Output is correct
36 Correct 194 ms 4736 KB Output is correct
37 Correct 164 ms 4736 KB Output is correct
38 Correct 188 ms 4768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 4608 KB Output is correct
2 Correct 27 ms 4608 KB Output is correct
3 Correct 30 ms 4736 KB Output is correct
4 Correct 29 ms 4736 KB Output is correct
5 Correct 26 ms 4608 KB Output is correct
6 Correct 25 ms 4608 KB Output is correct
7 Correct 31 ms 4608 KB Output is correct
8 Correct 29 ms 4608 KB Output is correct
9 Correct 27 ms 4764 KB Output is correct
10 Correct 25 ms 4608 KB Output is correct
11 Correct 26 ms 4728 KB Output is correct
12 Correct 29 ms 4608 KB Output is correct
13 Correct 32 ms 4736 KB Output is correct
14 Correct 28 ms 4736 KB Output is correct
15 Correct 28 ms 4736 KB Output is correct
16 Correct 31 ms 4736 KB Output is correct
17 Correct 29 ms 4608 KB Output is correct
18 Correct 31 ms 4856 KB Output is correct
19 Runtime error 33 ms 2960 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 4608 KB Output is correct
2 Correct 27 ms 4608 KB Output is correct
3 Correct 30 ms 4736 KB Output is correct
4 Correct 29 ms 4736 KB Output is correct
5 Correct 26 ms 4608 KB Output is correct
6 Correct 25 ms 4608 KB Output is correct
7 Correct 31 ms 4608 KB Output is correct
8 Correct 29 ms 4608 KB Output is correct
9 Correct 27 ms 4764 KB Output is correct
10 Correct 25 ms 4608 KB Output is correct
11 Correct 26 ms 4728 KB Output is correct
12 Correct 29 ms 4608 KB Output is correct
13 Correct 32 ms 4736 KB Output is correct
14 Correct 28 ms 4736 KB Output is correct
15 Correct 28 ms 4736 KB Output is correct
16 Correct 31 ms 4736 KB Output is correct
17 Correct 29 ms 4608 KB Output is correct
18 Correct 31 ms 4856 KB Output is correct
19 Correct 8 ms 4736 KB Output is correct
20 Correct 27 ms 4736 KB Output is correct
21 Correct 224 ms 4856 KB Output is correct
22 Correct 227 ms 4768 KB Output is correct
23 Correct 203 ms 4736 KB Output is correct
24 Correct 219 ms 4856 KB Output is correct
25 Correct 238 ms 4772 KB Output is correct
26 Correct 242 ms 4736 KB Output is correct
27 Correct 240 ms 4736 KB Output is correct
28 Correct 230 ms 4856 KB Output is correct
29 Correct 209 ms 4736 KB Output is correct
30 Correct 203 ms 4736 KB Output is correct
31 Correct 216 ms 4856 KB Output is correct
32 Correct 218 ms 4736 KB Output is correct
33 Correct 220 ms 4736 KB Output is correct
34 Correct 230 ms 4784 KB Output is correct
35 Correct 193 ms 4736 KB Output is correct
36 Correct 194 ms 4736 KB Output is correct
37 Correct 164 ms 4736 KB Output is correct
38 Correct 188 ms 4768 KB Output is correct
39 Runtime error 33 ms 2960 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Halted 0 ms 0 KB -