답안 #402502

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
402502 2021-05-11T19:27:27 Z JerryLiu06 경주 (Race) (IOI11_race) C++17
100 / 100
600 ms 93948 KB
#include <bits/stdc++.h>
#include "race.h"
 
using namespace std;
 
using ll = long long;
using db = long double;
using str = string;
 
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
 
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
 
#define mp make_pair
#define f first
#define s second

#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
 
#define lb lower_bound
#define ub upper_bound
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)

const int MOD = 1e9 + 7;
const int MX = 2e5 + 10;
const ll INF = 1e18;

int N, K; ll ans; vpi adj[MX]; unordered_map<ll, ll> M[MX];

void DFS(int X, int P, ll dist, ll depth) {
    M[X][dist] = depth; EACH(Y, adj[X]) if (Y.f != P) {
        DFS(Y.f, X, dist + Y.s, depth + 1); if (sz(M[X]) < sz(M[Y.f])) swap(M[X], M[Y.f]);
        
        EACH(C, M[Y.f]) if (M[X].count(K + 2 * dist - C.f)) ans = min(ans, M[X][K + 2 * dist - C.f] + C.s - 2 * depth);

        EACH(C, M[Y.f]) { if (!M[X].count(C.f)) M[X][C.f] = C.s; else M[X][C.f] = min(M[X][C.f], C.s); }
    }
}
int best_path(int _N, int _K, int H[][2], int L[]) {
    N = _N; K = _K; F0R(i, N - 1) { 
        int A = H[i][0]; int B = H[i][1]; 
        
        adj[A].pb({B, L[i]}), adj[B].pb({A, L[i]});
    }
    ans = INF; DFS(0, -1, 0, 0); return (ans == INF ? -1 : ans);
}

// int main() {
//     ios_base::sync_with_stdio(false); cin.tie(0);

//     cin >> N >> K; F0R(i, N - 1) { int A, B, C; cin >> A >> B >> C; adj[A].pb({B, C}), adj[B].pb({A, C}); }

//     ans = INF; DFS(0, -1, 0, 0); cout << ans;
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 15948 KB Output is correct
2 Correct 11 ms 15948 KB Output is correct
3 Correct 12 ms 15960 KB Output is correct
4 Correct 11 ms 15996 KB Output is correct
5 Correct 12 ms 15944 KB Output is correct
6 Correct 11 ms 15960 KB Output is correct
7 Correct 13 ms 15948 KB Output is correct
8 Correct 14 ms 15956 KB Output is correct
9 Correct 13 ms 16000 KB Output is correct
10 Correct 12 ms 15948 KB Output is correct
11 Correct 12 ms 15968 KB Output is correct
12 Correct 12 ms 15948 KB Output is correct
13 Correct 11 ms 15968 KB Output is correct
14 Correct 11 ms 15948 KB Output is correct
15 Correct 11 ms 15980 KB Output is correct
16 Correct 11 ms 15956 KB Output is correct
17 Correct 12 ms 15992 KB Output is correct
18 Correct 12 ms 15960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 15948 KB Output is correct
2 Correct 11 ms 15948 KB Output is correct
3 Correct 12 ms 15960 KB Output is correct
4 Correct 11 ms 15996 KB Output is correct
5 Correct 12 ms 15944 KB Output is correct
6 Correct 11 ms 15960 KB Output is correct
7 Correct 13 ms 15948 KB Output is correct
8 Correct 14 ms 15956 KB Output is correct
9 Correct 13 ms 16000 KB Output is correct
10 Correct 12 ms 15948 KB Output is correct
11 Correct 12 ms 15968 KB Output is correct
12 Correct 12 ms 15948 KB Output is correct
13 Correct 11 ms 15968 KB Output is correct
14 Correct 11 ms 15948 KB Output is correct
15 Correct 11 ms 15980 KB Output is correct
16 Correct 11 ms 15956 KB Output is correct
17 Correct 12 ms 15992 KB Output is correct
18 Correct 12 ms 15960 KB Output is correct
19 Correct 12 ms 15980 KB Output is correct
20 Correct 11 ms 15972 KB Output is correct
21 Correct 14 ms 16136 KB Output is correct
22 Correct 13 ms 16228 KB Output is correct
23 Correct 13 ms 16204 KB Output is correct
24 Correct 13 ms 16204 KB Output is correct
25 Correct 13 ms 16204 KB Output is correct
26 Correct 13 ms 16204 KB Output is correct
27 Correct 13 ms 16096 KB Output is correct
28 Correct 13 ms 16228 KB Output is correct
29 Correct 15 ms 16284 KB Output is correct
30 Correct 14 ms 16168 KB Output is correct
31 Correct 13 ms 16228 KB Output is correct
32 Correct 13 ms 16228 KB Output is correct
33 Correct 14 ms 16224 KB Output is correct
34 Correct 12 ms 16256 KB Output is correct
35 Correct 12 ms 16152 KB Output is correct
36 Correct 13 ms 16204 KB Output is correct
37 Correct 13 ms 16224 KB Output is correct
38 Correct 13 ms 16164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 15948 KB Output is correct
2 Correct 11 ms 15948 KB Output is correct
3 Correct 12 ms 15960 KB Output is correct
4 Correct 11 ms 15996 KB Output is correct
5 Correct 12 ms 15944 KB Output is correct
6 Correct 11 ms 15960 KB Output is correct
7 Correct 13 ms 15948 KB Output is correct
8 Correct 14 ms 15956 KB Output is correct
9 Correct 13 ms 16000 KB Output is correct
10 Correct 12 ms 15948 KB Output is correct
11 Correct 12 ms 15968 KB Output is correct
12 Correct 12 ms 15948 KB Output is correct
13 Correct 11 ms 15968 KB Output is correct
14 Correct 11 ms 15948 KB Output is correct
15 Correct 11 ms 15980 KB Output is correct
16 Correct 11 ms 15956 KB Output is correct
17 Correct 12 ms 15992 KB Output is correct
18 Correct 12 ms 15960 KB Output is correct
19 Correct 146 ms 40296 KB Output is correct
20 Correct 151 ms 40336 KB Output is correct
21 Correct 150 ms 40032 KB Output is correct
22 Correct 154 ms 39840 KB Output is correct
23 Correct 176 ms 48220 KB Output is correct
24 Correct 149 ms 41960 KB Output is correct
25 Correct 182 ms 42960 KB Output is correct
26 Correct 92 ms 49988 KB Output is correct
27 Correct 259 ms 58432 KB Output is correct
28 Correct 366 ms 93260 KB Output is correct
29 Correct 402 ms 91780 KB Output is correct
30 Correct 264 ms 58432 KB Output is correct
31 Correct 323 ms 58396 KB Output is correct
32 Correct 373 ms 58344 KB Output is correct
33 Correct 273 ms 61636 KB Output is correct
34 Correct 479 ms 83600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 15948 KB Output is correct
2 Correct 11 ms 15948 KB Output is correct
3 Correct 12 ms 15960 KB Output is correct
4 Correct 11 ms 15996 KB Output is correct
5 Correct 12 ms 15944 KB Output is correct
6 Correct 11 ms 15960 KB Output is correct
7 Correct 13 ms 15948 KB Output is correct
8 Correct 14 ms 15956 KB Output is correct
9 Correct 13 ms 16000 KB Output is correct
10 Correct 12 ms 15948 KB Output is correct
11 Correct 12 ms 15968 KB Output is correct
12 Correct 12 ms 15948 KB Output is correct
13 Correct 11 ms 15968 KB Output is correct
14 Correct 11 ms 15948 KB Output is correct
15 Correct 11 ms 15980 KB Output is correct
16 Correct 11 ms 15956 KB Output is correct
17 Correct 12 ms 15992 KB Output is correct
18 Correct 12 ms 15960 KB Output is correct
19 Correct 12 ms 15980 KB Output is correct
20 Correct 11 ms 15972 KB Output is correct
21 Correct 14 ms 16136 KB Output is correct
22 Correct 13 ms 16228 KB Output is correct
23 Correct 13 ms 16204 KB Output is correct
24 Correct 13 ms 16204 KB Output is correct
25 Correct 13 ms 16204 KB Output is correct
26 Correct 13 ms 16204 KB Output is correct
27 Correct 13 ms 16096 KB Output is correct
28 Correct 13 ms 16228 KB Output is correct
29 Correct 15 ms 16284 KB Output is correct
30 Correct 14 ms 16168 KB Output is correct
31 Correct 13 ms 16228 KB Output is correct
32 Correct 13 ms 16228 KB Output is correct
33 Correct 14 ms 16224 KB Output is correct
34 Correct 12 ms 16256 KB Output is correct
35 Correct 12 ms 16152 KB Output is correct
36 Correct 13 ms 16204 KB Output is correct
37 Correct 13 ms 16224 KB Output is correct
38 Correct 13 ms 16164 KB Output is correct
39 Correct 146 ms 40296 KB Output is correct
40 Correct 151 ms 40336 KB Output is correct
41 Correct 150 ms 40032 KB Output is correct
42 Correct 154 ms 39840 KB Output is correct
43 Correct 176 ms 48220 KB Output is correct
44 Correct 149 ms 41960 KB Output is correct
45 Correct 182 ms 42960 KB Output is correct
46 Correct 92 ms 49988 KB Output is correct
47 Correct 259 ms 58432 KB Output is correct
48 Correct 366 ms 93260 KB Output is correct
49 Correct 402 ms 91780 KB Output is correct
50 Correct 264 ms 58432 KB Output is correct
51 Correct 323 ms 58396 KB Output is correct
52 Correct 373 ms 58344 KB Output is correct
53 Correct 273 ms 61636 KB Output is correct
54 Correct 479 ms 83600 KB Output is correct
55 Correct 27 ms 19060 KB Output is correct
56 Correct 21 ms 18096 KB Output is correct
57 Correct 108 ms 38448 KB Output is correct
58 Correct 81 ms 35112 KB Output is correct
59 Correct 107 ms 54620 KB Output is correct
60 Correct 372 ms 92324 KB Output is correct
61 Correct 274 ms 60720 KB Output is correct
62 Correct 264 ms 58356 KB Output is correct
63 Correct 385 ms 58308 KB Output is correct
64 Correct 559 ms 93948 KB Output is correct
65 Correct 600 ms 92856 KB Output is correct
66 Correct 374 ms 88068 KB Output is correct
67 Correct 235 ms 54352 KB Output is correct
68 Correct 466 ms 68792 KB Output is correct
69 Correct 472 ms 72240 KB Output is correct
70 Correct 423 ms 66644 KB Output is correct