답안 #637851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637851 2022-09-03T12:14:44 Z erto 경주 (Race) (IOI11_race) C++17
100 / 100
408 ms 114148 KB
#include <bits/stdc++.h>
#include "race.h"
typedef long long int ll;
#define INF (int)(1e9 + 7)
#define INF2 998244353
#define N (ll)(2e5 + 5)
using namespace std;
//#define int ll
#define lsb(x) (x & (-x))
 
ll n, k;
ll g;
ll ans = INF;
vector<pair<ll, ll>> v[N];
set<pair<ll, ll>> s[N];
ll d[N];
ll dis[N];
 
void dfs(int x, int p){
    for(auto u : v[x]){
        if(u.first != p){
            d[u.first] = d[x] + 1;
            dis[u.first] = dis[x] + u.second;
            dfs(u.first, x);
        }
    }
 
    s[x].insert({dis[x], d[x]});
 
    for(auto u : v[x]){
        if(u.first != p){
            if(s[x].size() < s[u.first].size()){
                swap(s[x], s[u.first]);
            }
 
            for(auto j : s[u.first]){
                g = k - (j.first - dis[x]) + dis[x];
                auto it = s[x].lower_bound(make_pair(g, 0ll));
                if(it != s[x].end() && it->first == g){
                    ans = min(ans, j.second + it->second - 2 * d[x]);
                }
            }
            for(auto j : s[u.first])s[x].insert(j);
        }
    }
}
 
int best_path(int nn, int K, int H[][2], int L[]){
    n = nn;
    for(int i=0; i<n-1; i++){
        v[H[i][0]].push_back({H[i][1], L[i]});
        v[H[i][1]].push_back({H[i][0], L[i]});
    }
 
    k=K;
    dfs(0, -1);
    if(ans == INF)return -1;
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14460 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 8 ms 14348 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14452 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14428 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14460 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 8 ms 14348 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14452 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14428 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 7 ms 14420 KB Output is correct
20 Correct 7 ms 14448 KB Output is correct
21 Correct 8 ms 14676 KB Output is correct
22 Correct 8 ms 14764 KB Output is correct
23 Correct 8 ms 14752 KB Output is correct
24 Correct 9 ms 14676 KB Output is correct
25 Correct 8 ms 14708 KB Output is correct
26 Correct 8 ms 14676 KB Output is correct
27 Correct 8 ms 14548 KB Output is correct
28 Correct 8 ms 14680 KB Output is correct
29 Correct 8 ms 14676 KB Output is correct
30 Correct 8 ms 14736 KB Output is correct
31 Correct 10 ms 14676 KB Output is correct
32 Correct 8 ms 14676 KB Output is correct
33 Correct 8 ms 14772 KB Output is correct
34 Correct 9 ms 14676 KB Output is correct
35 Correct 8 ms 14636 KB Output is correct
36 Correct 8 ms 14676 KB Output is correct
37 Correct 8 ms 14548 KB Output is correct
38 Correct 8 ms 14640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14460 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 8 ms 14348 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14452 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14428 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 130 ms 42652 KB Output is correct
20 Correct 135 ms 42608 KB Output is correct
21 Correct 135 ms 41936 KB Output is correct
22 Correct 126 ms 40500 KB Output is correct
23 Correct 169 ms 55064 KB Output is correct
24 Correct 132 ms 41076 KB Output is correct
25 Correct 130 ms 46356 KB Output is correct
26 Correct 89 ms 51540 KB Output is correct
27 Correct 198 ms 52828 KB Output is correct
28 Correct 284 ms 88648 KB Output is correct
29 Correct 273 ms 87200 KB Output is correct
30 Correct 207 ms 52868 KB Output is correct
31 Correct 191 ms 52728 KB Output is correct
32 Correct 286 ms 52732 KB Output is correct
33 Correct 228 ms 54624 KB Output is correct
34 Correct 321 ms 86468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14460 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 8 ms 14348 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14452 KB Output is correct
15 Correct 7 ms 14420 KB Output is correct
16 Correct 8 ms 14428 KB Output is correct
17 Correct 7 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 7 ms 14420 KB Output is correct
20 Correct 7 ms 14448 KB Output is correct
21 Correct 8 ms 14676 KB Output is correct
22 Correct 8 ms 14764 KB Output is correct
23 Correct 8 ms 14752 KB Output is correct
24 Correct 9 ms 14676 KB Output is correct
25 Correct 8 ms 14708 KB Output is correct
26 Correct 8 ms 14676 KB Output is correct
27 Correct 8 ms 14548 KB Output is correct
28 Correct 8 ms 14680 KB Output is correct
29 Correct 8 ms 14676 KB Output is correct
30 Correct 8 ms 14736 KB Output is correct
31 Correct 10 ms 14676 KB Output is correct
32 Correct 8 ms 14676 KB Output is correct
33 Correct 8 ms 14772 KB Output is correct
34 Correct 9 ms 14676 KB Output is correct
35 Correct 8 ms 14636 KB Output is correct
36 Correct 8 ms 14676 KB Output is correct
37 Correct 8 ms 14548 KB Output is correct
38 Correct 8 ms 14640 KB Output is correct
39 Correct 130 ms 42652 KB Output is correct
40 Correct 135 ms 42608 KB Output is correct
41 Correct 135 ms 41936 KB Output is correct
42 Correct 126 ms 40500 KB Output is correct
43 Correct 169 ms 55064 KB Output is correct
44 Correct 132 ms 41076 KB Output is correct
45 Correct 130 ms 46356 KB Output is correct
46 Correct 89 ms 51540 KB Output is correct
47 Correct 198 ms 52828 KB Output is correct
48 Correct 284 ms 88648 KB Output is correct
49 Correct 273 ms 87200 KB Output is correct
50 Correct 207 ms 52868 KB Output is correct
51 Correct 191 ms 52728 KB Output is correct
52 Correct 286 ms 52732 KB Output is correct
53 Correct 228 ms 54624 KB Output is correct
54 Correct 321 ms 86468 KB Output is correct
55 Correct 20 ms 17900 KB Output is correct
56 Correct 16 ms 16724 KB Output is correct
57 Correct 83 ms 37500 KB Output is correct
58 Correct 49 ms 29112 KB Output is correct
59 Correct 97 ms 52904 KB Output is correct
60 Correct 267 ms 90508 KB Output is correct
61 Correct 217 ms 61480 KB Output is correct
62 Correct 211 ms 55812 KB Output is correct
63 Correct 271 ms 55796 KB Output is correct
64 Correct 408 ms 114148 KB Output is correct
65 Correct 392 ms 105824 KB Output is correct
66 Correct 291 ms 86672 KB Output is correct
67 Correct 159 ms 45492 KB Output is correct
68 Correct 324 ms 70568 KB Output is correct
69 Correct 335 ms 76064 KB Output is correct
70 Correct 317 ms 68264 KB Output is correct