답안 #310875

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
310875 2020-10-08T10:07:50 Z lohacho 경주 (Race) (IOI11_race) C++14
21 / 100
3000 ms 49004 KB
#include "race.h"

#include <bits/stdc++.h>

using namespace std;

using LL = long long;
const LL MOD = (LL)1e9 + 7;
const LL NS = (LL)2e5 + 4;
LL N, k;
vector<pair<LL, LL>> way[NS];
LL chk[NS], sz[NS], rt;
LL dis[(LL)1e6 + 4];
LL ans;
vector<LL> did;
vector<pair<LL, LL>> put;

void getroot(LL now, LL pr, LL alls){
    sz[now] = 1;
    LL f = 1;
    for(auto&nxt:way[now]){
        if(nxt.first == pr || chk[nxt.first]){
            continue;
        }
        getroot(nxt.first, now, alls);
        sz[now] += sz[nxt.first];
        if(sz[nxt.first] > alls / 2){
            f = 0;
        }
    }
    if(f){
        rt = now;
    }
}

void getdis(LL now, LL ndis, LL pr, LL ndep){
    LL need = k - ndis;
    if(need >= 0){
        ans = min(ans, ndep + dis[need]);
    }
    for(auto&nxt:way[now]){
        if(nxt.first == pr || chk[nxt.first]){
            continue;
        }
        getdis(nxt.first, ndis + nxt.second, now, ndep + 1);
    }
    if(ndis < (LL)1e6 + 4){
        if(dis[ndis] > ndep){
            put.push_back({ndis, ndep});
            did.push_back(ndis);
        }
    }
}

void sol(LL now, LL alls){
    dis[0] = 0;
    chk[now] = 1;
    did.clear();
    for(LL i = 0; i < (LL)way[now].size(); ++i){
        if(chk[way[now][i].first]){
            continue;
        }
        getdis(way[now][i].first, way[now][i].second, now, 1);
        while((LL)put.size()){
            dis[put.back().first] = min(dis[put.back().first], put.back().second);
            put.pop_back();
        }
    }
    while((LL)did.size()){
        dis[did.back()] = MOD;
        did.pop_back();
    }
    for(auto&nxt:way[now]){
        if(chk[nxt.first]){
            continue;
        }
        LL nsz = (sz[nxt.first] > sz[now] ? alls - sz[now]:sz[nxt.first]);
        getroot(nxt.first, now, nsz);
        sol(rt, nsz);
    }
}


int best_path(int n, int K, int H[][2], int L[])
{
    for(LL i = 0; i < (LL)1e6 + 4; ++i){
        dis[i] = MOD;
    }
    ans = MOD;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    N = n, k = K;
    for(LL i = 0; i < N - 1; ++i){
        LL a, b, c;
        a = H[i][0], b = H[i][1], c = L[i];
        way[a].push_back({b, c}), way[b].push_back({a, c});
    }
    getroot(1, -1, N);
    sol(rt, N);
    if(ans == MOD){
        return -1;
    }
    else{
        return ans;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 12928 KB Output is correct
2 Correct 9 ms 12928 KB Output is correct
3 Correct 9 ms 12928 KB Output is correct
4 Correct 9 ms 12928 KB Output is correct
5 Correct 8 ms 12928 KB Output is correct
6 Correct 10 ms 12928 KB Output is correct
7 Correct 9 ms 12928 KB Output is correct
8 Correct 9 ms 12928 KB Output is correct
9 Correct 9 ms 12928 KB Output is correct
10 Correct 8 ms 12928 KB Output is correct
11 Correct 9 ms 12928 KB Output is correct
12 Correct 9 ms 12928 KB Output is correct
13 Correct 8 ms 12928 KB Output is correct
14 Correct 9 ms 12928 KB Output is correct
15 Correct 9 ms 12928 KB Output is correct
16 Correct 9 ms 12928 KB Output is correct
17 Correct 9 ms 12928 KB Output is correct
18 Correct 10 ms 12928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 12928 KB Output is correct
2 Correct 9 ms 12928 KB Output is correct
3 Correct 9 ms 12928 KB Output is correct
4 Correct 9 ms 12928 KB Output is correct
5 Correct 8 ms 12928 KB Output is correct
6 Correct 10 ms 12928 KB Output is correct
7 Correct 9 ms 12928 KB Output is correct
8 Correct 9 ms 12928 KB Output is correct
9 Correct 9 ms 12928 KB Output is correct
10 Correct 8 ms 12928 KB Output is correct
11 Correct 9 ms 12928 KB Output is correct
12 Correct 9 ms 12928 KB Output is correct
13 Correct 8 ms 12928 KB Output is correct
14 Correct 9 ms 12928 KB Output is correct
15 Correct 9 ms 12928 KB Output is correct
16 Correct 9 ms 12928 KB Output is correct
17 Correct 9 ms 12928 KB Output is correct
18 Correct 10 ms 12928 KB Output is correct
19 Correct 9 ms 12928 KB Output is correct
20 Correct 9 ms 12928 KB Output is correct
21 Correct 11 ms 13056 KB Output is correct
22 Correct 10 ms 12928 KB Output is correct
23 Correct 11 ms 12928 KB Output is correct
24 Correct 10 ms 12928 KB Output is correct
25 Correct 12 ms 12928 KB Output is correct
26 Correct 11 ms 12928 KB Output is correct
27 Correct 10 ms 12928 KB Output is correct
28 Correct 12 ms 13056 KB Output is correct
29 Correct 11 ms 13056 KB Output is correct
30 Correct 12 ms 13056 KB Output is correct
31 Correct 12 ms 12960 KB Output is correct
32 Correct 11 ms 13056 KB Output is correct
33 Correct 13 ms 12960 KB Output is correct
34 Correct 10 ms 13056 KB Output is correct
35 Correct 10 ms 12928 KB Output is correct
36 Correct 10 ms 12928 KB Output is correct
37 Correct 10 ms 13056 KB Output is correct
38 Correct 12 ms 13184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 12928 KB Output is correct
2 Correct 9 ms 12928 KB Output is correct
3 Correct 9 ms 12928 KB Output is correct
4 Correct 9 ms 12928 KB Output is correct
5 Correct 8 ms 12928 KB Output is correct
6 Correct 10 ms 12928 KB Output is correct
7 Correct 9 ms 12928 KB Output is correct
8 Correct 9 ms 12928 KB Output is correct
9 Correct 9 ms 12928 KB Output is correct
10 Correct 8 ms 12928 KB Output is correct
11 Correct 9 ms 12928 KB Output is correct
12 Correct 9 ms 12928 KB Output is correct
13 Correct 8 ms 12928 KB Output is correct
14 Correct 9 ms 12928 KB Output is correct
15 Correct 9 ms 12928 KB Output is correct
16 Correct 9 ms 12928 KB Output is correct
17 Correct 9 ms 12928 KB Output is correct
18 Correct 10 ms 12928 KB Output is correct
19 Correct 466 ms 24040 KB Output is correct
20 Correct 359 ms 21616 KB Output is correct
21 Correct 348 ms 24168 KB Output is correct
22 Correct 2738 ms 24428 KB Output is correct
23 Correct 403 ms 24720 KB Output is correct
24 Correct 335 ms 23652 KB Output is correct
25 Correct 184 ms 29036 KB Output is correct
26 Correct 104 ms 29840 KB Output is correct
27 Correct 296 ms 33824 KB Output is correct
28 Correct 610 ms 49004 KB Output is correct
29 Correct 577 ms 39536 KB Output is correct
30 Correct 285 ms 33828 KB Output is correct
31 Correct 283 ms 33828 KB Output is correct
32 Execution timed out 3075 ms 34780 KB Time limit exceeded
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 12928 KB Output is correct
2 Correct 9 ms 12928 KB Output is correct
3 Correct 9 ms 12928 KB Output is correct
4 Correct 9 ms 12928 KB Output is correct
5 Correct 8 ms 12928 KB Output is correct
6 Correct 10 ms 12928 KB Output is correct
7 Correct 9 ms 12928 KB Output is correct
8 Correct 9 ms 12928 KB Output is correct
9 Correct 9 ms 12928 KB Output is correct
10 Correct 8 ms 12928 KB Output is correct
11 Correct 9 ms 12928 KB Output is correct
12 Correct 9 ms 12928 KB Output is correct
13 Correct 8 ms 12928 KB Output is correct
14 Correct 9 ms 12928 KB Output is correct
15 Correct 9 ms 12928 KB Output is correct
16 Correct 9 ms 12928 KB Output is correct
17 Correct 9 ms 12928 KB Output is correct
18 Correct 10 ms 12928 KB Output is correct
19 Correct 9 ms 12928 KB Output is correct
20 Correct 9 ms 12928 KB Output is correct
21 Correct 11 ms 13056 KB Output is correct
22 Correct 10 ms 12928 KB Output is correct
23 Correct 11 ms 12928 KB Output is correct
24 Correct 10 ms 12928 KB Output is correct
25 Correct 12 ms 12928 KB Output is correct
26 Correct 11 ms 12928 KB Output is correct
27 Correct 10 ms 12928 KB Output is correct
28 Correct 12 ms 13056 KB Output is correct
29 Correct 11 ms 13056 KB Output is correct
30 Correct 12 ms 13056 KB Output is correct
31 Correct 12 ms 12960 KB Output is correct
32 Correct 11 ms 13056 KB Output is correct
33 Correct 13 ms 12960 KB Output is correct
34 Correct 10 ms 13056 KB Output is correct
35 Correct 10 ms 12928 KB Output is correct
36 Correct 10 ms 12928 KB Output is correct
37 Correct 10 ms 13056 KB Output is correct
38 Correct 12 ms 13184 KB Output is correct
39 Correct 466 ms 24040 KB Output is correct
40 Correct 359 ms 21616 KB Output is correct
41 Correct 348 ms 24168 KB Output is correct
42 Correct 2738 ms 24428 KB Output is correct
43 Correct 403 ms 24720 KB Output is correct
44 Correct 335 ms 23652 KB Output is correct
45 Correct 184 ms 29036 KB Output is correct
46 Correct 104 ms 29840 KB Output is correct
47 Correct 296 ms 33824 KB Output is correct
48 Correct 610 ms 49004 KB Output is correct
49 Correct 577 ms 39536 KB Output is correct
50 Correct 285 ms 33828 KB Output is correct
51 Correct 283 ms 33828 KB Output is correct
52 Execution timed out 3075 ms 34780 KB Time limit exceeded
53 Halted 0 ms 0 KB -