답안 #774558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
774558 2023-07-05T19:55:47 Z teokakabadze 경주 (Race) (IOI11_race) C++17
100 / 100
431 ms 84604 KB
#include "race.h"
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define n 200005
#define pii pair<int, int>
using namespace std;

int ans = 1e9, i, k, s[n], h[n];
vector<pii> v[n];
map<int, int> m[n];

void dfs(int u, int p)
{
    for(auto x : v[u])
    if(x.f != p)
    {
        s[x.f] = s[u] + x.s;
        h[x.f] = h[u] + 1;
        m[x.f][s[x.f]] = h[x.f];
        dfs(x.f, u);
    }
}

void dfs1(int u, int p)
{
    for(auto x : v[u])
    if(x.f != p)
    {
        dfs1(x.f, u);
        if(m[x.f].size() > m[u].size()) swap(m[u], m[x.f]);
        for(auto y : m[x.f])
        if(m[u].find(k + 2 * s[u] - y.f) != m[u].end()) ans = min(ans, m[u][k + 2 * s[u] - y.f] + y.s - 2 * h[u]);
        for(auto y : m[x.f])
        if(m[u].find(y.f) != m[u].end()) m[u][y.f] = min(m[u][y.f], y.s);
        else m[u][y.f] = y.s;
    }
}

int best_path(int N, int K, int H[][2], int L[])
{
    k = K;
    for(i = 0; i < N - 1; i++)
    {
        v[H[i][0]].pb({H[i][1], L[i]});
        v[H[i][1]].pb({H[i][0], L[i]});
    }
    m[0][0] = 0;
    dfs(0, 0);
    dfs1(0, 0);
    if(ans == 1e9) return -1;
    return ans;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 9 ms 14404 KB Output is correct
3 Correct 9 ms 14404 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 8 ms 14336 KB Output is correct
7 Correct 7 ms 14404 KB Output is correct
8 Correct 9 ms 14376 KB Output is correct
9 Correct 7 ms 14400 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 7 ms 14324 KB Output is correct
13 Correct 7 ms 14404 KB Output is correct
14 Correct 9 ms 14420 KB Output is correct
15 Correct 7 ms 14380 KB Output is correct
16 Correct 9 ms 14404 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 9 ms 14404 KB Output is correct
3 Correct 9 ms 14404 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 8 ms 14336 KB Output is correct
7 Correct 7 ms 14404 KB Output is correct
8 Correct 9 ms 14376 KB Output is correct
9 Correct 7 ms 14400 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 7 ms 14324 KB Output is correct
13 Correct 7 ms 14404 KB Output is correct
14 Correct 9 ms 14420 KB Output is correct
15 Correct 7 ms 14380 KB Output is correct
16 Correct 9 ms 14404 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 9 ms 14404 KB Output is correct
20 Correct 8 ms 14420 KB Output is correct
21 Correct 9 ms 14548 KB Output is correct
22 Correct 10 ms 14672 KB Output is correct
23 Correct 11 ms 14676 KB Output is correct
24 Correct 10 ms 14632 KB Output is correct
25 Correct 9 ms 14544 KB Output is correct
26 Correct 8 ms 14548 KB Output is correct
27 Correct 9 ms 14544 KB Output is correct
28 Correct 8 ms 14632 KB Output is correct
29 Correct 10 ms 14672 KB Output is correct
30 Correct 8 ms 14548 KB Output is correct
31 Correct 9 ms 14548 KB Output is correct
32 Correct 8 ms 14544 KB Output is correct
33 Correct 8 ms 14676 KB Output is correct
34 Correct 8 ms 14548 KB Output is correct
35 Correct 8 ms 14532 KB Output is correct
36 Correct 8 ms 14544 KB Output is correct
37 Correct 8 ms 14548 KB Output is correct
38 Correct 8 ms 14548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 9 ms 14404 KB Output is correct
3 Correct 9 ms 14404 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 8 ms 14336 KB Output is correct
7 Correct 7 ms 14404 KB Output is correct
8 Correct 9 ms 14376 KB Output is correct
9 Correct 7 ms 14400 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 7 ms 14324 KB Output is correct
13 Correct 7 ms 14404 KB Output is correct
14 Correct 9 ms 14420 KB Output is correct
15 Correct 7 ms 14380 KB Output is correct
16 Correct 9 ms 14404 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 112 ms 33064 KB Output is correct
20 Correct 107 ms 33060 KB Output is correct
21 Correct 118 ms 32840 KB Output is correct
22 Correct 108 ms 32524 KB Output is correct
23 Correct 177 ms 42184 KB Output is correct
24 Correct 106 ms 35104 KB Output is correct
25 Correct 92 ms 34284 KB Output is correct
26 Correct 52 ms 41120 KB Output is correct
27 Correct 172 ms 43072 KB Output is correct
28 Correct 240 ms 77644 KB Output is correct
29 Correct 249 ms 76032 KB Output is correct
30 Correct 160 ms 43012 KB Output is correct
31 Correct 165 ms 43128 KB Output is correct
32 Correct 244 ms 43136 KB Output is correct
33 Correct 239 ms 46488 KB Output is correct
34 Correct 313 ms 71560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 9 ms 14404 KB Output is correct
3 Correct 9 ms 14404 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 8 ms 14336 KB Output is correct
7 Correct 7 ms 14404 KB Output is correct
8 Correct 9 ms 14376 KB Output is correct
9 Correct 7 ms 14400 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 7 ms 14324 KB Output is correct
13 Correct 7 ms 14404 KB Output is correct
14 Correct 9 ms 14420 KB Output is correct
15 Correct 7 ms 14380 KB Output is correct
16 Correct 9 ms 14404 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 9 ms 14404 KB Output is correct
20 Correct 8 ms 14420 KB Output is correct
21 Correct 9 ms 14548 KB Output is correct
22 Correct 10 ms 14672 KB Output is correct
23 Correct 11 ms 14676 KB Output is correct
24 Correct 10 ms 14632 KB Output is correct
25 Correct 9 ms 14544 KB Output is correct
26 Correct 8 ms 14548 KB Output is correct
27 Correct 9 ms 14544 KB Output is correct
28 Correct 8 ms 14632 KB Output is correct
29 Correct 10 ms 14672 KB Output is correct
30 Correct 8 ms 14548 KB Output is correct
31 Correct 9 ms 14548 KB Output is correct
32 Correct 8 ms 14544 KB Output is correct
33 Correct 8 ms 14676 KB Output is correct
34 Correct 8 ms 14548 KB Output is correct
35 Correct 8 ms 14532 KB Output is correct
36 Correct 8 ms 14544 KB Output is correct
37 Correct 8 ms 14548 KB Output is correct
38 Correct 8 ms 14548 KB Output is correct
39 Correct 112 ms 33064 KB Output is correct
40 Correct 107 ms 33060 KB Output is correct
41 Correct 118 ms 32840 KB Output is correct
42 Correct 108 ms 32524 KB Output is correct
43 Correct 177 ms 42184 KB Output is correct
44 Correct 106 ms 35104 KB Output is correct
45 Correct 92 ms 34284 KB Output is correct
46 Correct 52 ms 41120 KB Output is correct
47 Correct 172 ms 43072 KB Output is correct
48 Correct 240 ms 77644 KB Output is correct
49 Correct 249 ms 76032 KB Output is correct
50 Correct 160 ms 43012 KB Output is correct
51 Correct 165 ms 43128 KB Output is correct
52 Correct 244 ms 43136 KB Output is correct
53 Correct 239 ms 46488 KB Output is correct
54 Correct 313 ms 71560 KB Output is correct
55 Correct 19 ms 16980 KB Output is correct
56 Correct 13 ms 15948 KB Output is correct
57 Correct 60 ms 31068 KB Output is correct
58 Correct 46 ms 25920 KB Output is correct
59 Correct 72 ms 45824 KB Output is correct
60 Correct 227 ms 76400 KB Output is correct
61 Correct 209 ms 45792 KB Output is correct
62 Correct 166 ms 43132 KB Output is correct
63 Correct 233 ms 43232 KB Output is correct
64 Correct 412 ms 84604 KB Output is correct
65 Correct 431 ms 83292 KB Output is correct
66 Correct 254 ms 72524 KB Output is correct
67 Correct 176 ms 39112 KB Output is correct
68 Correct 296 ms 56092 KB Output is correct
69 Correct 340 ms 59928 KB Output is correct
70 Correct 305 ms 54348 KB Output is correct