답안 #551238

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551238 2022-04-20T06:15:19 Z Keshi 경주 (Race) (IOI11_race) C++17
100 / 100
453 ms 100560 KB
//In the name of God
#include "race.h"

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()


int n, k, d[maxn];
ll s[maxn], s2[maxn];
vector<pii> g[maxn];
map<ll, ll> mn[maxn];
ll ans = INF;

void dfs(int v, int p = -1){
	mn[v][0] = d[v];
	for(pii e : g[v]){
		int u = e.F;
		int c = e.S;
		if(u == p) continue;
		d[u] = d[v] + 1;
		dfs(u, v);
		s[u] += c;
		if(Sz(mn[v]) < Sz(mn[u])){
			mn[v].swap(mn[u]);
			swap(s[v], s[u]);
		}
		for(pll i : mn[u]){
			i.F += s[u];
			if(mn[v].find(k - i.F - s[v]) != mn[v].end()){
				ans = min(ans, i.S + mn[v][k - i.F - s[v]] - d[v] * 2);
			}
		}
		for(pll i : mn[u]){
			i.F += s[u];
			if(mn[v].find(i.F - s[v]) == mn[v].end()){
				mn[v][i.F - s[v]] = i.S;
			}
			else mn[v][i.F - s[v]] = min(mn[v][i.F - s[v]], i.S);
		}
	}
	return;
}

int best_path(int N, int K, int H[][2], int L[]){
	n = N;
	k = K;
	for(int i = 0; i < n - 1; i++){
		int v = H[i][0], u = H[i][1];
		g[v].pb(Mp(u, L[i]));
		g[u].pb(Mp(v, L[i]));
	}
	dfs(0);
	if(ans == INF) return -1;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 8 ms 14424 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 7 ms 14412 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14452 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 8 ms 14412 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14420 KB Output is correct
13 Correct 8 ms 14420 KB Output is correct
14 Correct 8 ms 14408 KB Output is correct
15 Correct 9 ms 14404 KB Output is correct
16 Correct 9 ms 14420 KB Output is correct
17 Correct 7 ms 14432 KB Output is correct
18 Correct 8 ms 14408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 8 ms 14424 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 7 ms 14412 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14452 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 8 ms 14412 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14420 KB Output is correct
13 Correct 8 ms 14420 KB Output is correct
14 Correct 8 ms 14408 KB Output is correct
15 Correct 9 ms 14404 KB Output is correct
16 Correct 9 ms 14420 KB Output is correct
17 Correct 7 ms 14432 KB Output is correct
18 Correct 8 ms 14408 KB Output is correct
19 Correct 8 ms 14328 KB Output is correct
20 Correct 7 ms 14412 KB Output is correct
21 Correct 10 ms 14680 KB Output is correct
22 Correct 8 ms 14676 KB Output is correct
23 Correct 9 ms 14708 KB Output is correct
24 Correct 9 ms 14684 KB Output is correct
25 Correct 9 ms 14680 KB Output is correct
26 Correct 10 ms 14676 KB Output is correct
27 Correct 8 ms 14496 KB Output is correct
28 Correct 9 ms 14676 KB Output is correct
29 Correct 9 ms 14724 KB Output is correct
30 Correct 10 ms 14748 KB Output is correct
31 Correct 10 ms 14680 KB Output is correct
32 Correct 9 ms 14676 KB Output is correct
33 Correct 9 ms 14676 KB Output is correct
34 Correct 9 ms 14680 KB Output is correct
35 Correct 9 ms 14676 KB Output is correct
36 Correct 12 ms 14648 KB Output is correct
37 Correct 10 ms 14548 KB Output is correct
38 Correct 9 ms 14676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 8 ms 14424 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 7 ms 14412 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14452 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 8 ms 14412 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14420 KB Output is correct
13 Correct 8 ms 14420 KB Output is correct
14 Correct 8 ms 14408 KB Output is correct
15 Correct 9 ms 14404 KB Output is correct
16 Correct 9 ms 14420 KB Output is correct
17 Correct 7 ms 14432 KB Output is correct
18 Correct 8 ms 14408 KB Output is correct
19 Correct 127 ms 36180 KB Output is correct
20 Correct 129 ms 36184 KB Output is correct
21 Correct 147 ms 36024 KB Output is correct
22 Correct 151 ms 35372 KB Output is correct
23 Correct 166 ms 48028 KB Output is correct
24 Correct 133 ms 38684 KB Output is correct
25 Correct 113 ms 35020 KB Output is correct
26 Correct 80 ms 41800 KB Output is correct
27 Correct 188 ms 45640 KB Output is correct
28 Correct 330 ms 81648 KB Output is correct
29 Correct 286 ms 80232 KB Output is correct
30 Correct 197 ms 45644 KB Output is correct
31 Correct 208 ms 45800 KB Output is correct
32 Correct 266 ms 45808 KB Output is correct
33 Correct 252 ms 50720 KB Output is correct
34 Correct 340 ms 82720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 8 ms 14424 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 7 ms 14412 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Correct 7 ms 14420 KB Output is correct
8 Correct 7 ms 14452 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 8 ms 14412 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14420 KB Output is correct
13 Correct 8 ms 14420 KB Output is correct
14 Correct 8 ms 14408 KB Output is correct
15 Correct 9 ms 14404 KB Output is correct
16 Correct 9 ms 14420 KB Output is correct
17 Correct 7 ms 14432 KB Output is correct
18 Correct 8 ms 14408 KB Output is correct
19 Correct 8 ms 14328 KB Output is correct
20 Correct 7 ms 14412 KB Output is correct
21 Correct 10 ms 14680 KB Output is correct
22 Correct 8 ms 14676 KB Output is correct
23 Correct 9 ms 14708 KB Output is correct
24 Correct 9 ms 14684 KB Output is correct
25 Correct 9 ms 14680 KB Output is correct
26 Correct 10 ms 14676 KB Output is correct
27 Correct 8 ms 14496 KB Output is correct
28 Correct 9 ms 14676 KB Output is correct
29 Correct 9 ms 14724 KB Output is correct
30 Correct 10 ms 14748 KB Output is correct
31 Correct 10 ms 14680 KB Output is correct
32 Correct 9 ms 14676 KB Output is correct
33 Correct 9 ms 14676 KB Output is correct
34 Correct 9 ms 14680 KB Output is correct
35 Correct 9 ms 14676 KB Output is correct
36 Correct 12 ms 14648 KB Output is correct
37 Correct 10 ms 14548 KB Output is correct
38 Correct 9 ms 14676 KB Output is correct
39 Correct 127 ms 36180 KB Output is correct
40 Correct 129 ms 36184 KB Output is correct
41 Correct 147 ms 36024 KB Output is correct
42 Correct 151 ms 35372 KB Output is correct
43 Correct 166 ms 48028 KB Output is correct
44 Correct 133 ms 38684 KB Output is correct
45 Correct 113 ms 35020 KB Output is correct
46 Correct 80 ms 41800 KB Output is correct
47 Correct 188 ms 45640 KB Output is correct
48 Correct 330 ms 81648 KB Output is correct
49 Correct 286 ms 80232 KB Output is correct
50 Correct 197 ms 45644 KB Output is correct
51 Correct 208 ms 45800 KB Output is correct
52 Correct 266 ms 45808 KB Output is correct
53 Correct 252 ms 50720 KB Output is correct
54 Correct 340 ms 82720 KB Output is correct
55 Correct 22 ms 17516 KB Output is correct
56 Correct 14 ms 16212 KB Output is correct
57 Correct 76 ms 33304 KB Output is correct
58 Correct 59 ms 26864 KB Output is correct
59 Correct 91 ms 48028 KB Output is correct
60 Correct 310 ms 80752 KB Output is correct
61 Correct 235 ms 48996 KB Output is correct
62 Correct 195 ms 45808 KB Output is correct
63 Correct 277 ms 45792 KB Output is correct
64 Correct 453 ms 100560 KB Output is correct
65 Correct 448 ms 98172 KB Output is correct
66 Correct 324 ms 77120 KB Output is correct
67 Correct 187 ms 39664 KB Output is correct
68 Correct 370 ms 61988 KB Output is correct
69 Correct 422 ms 67188 KB Output is correct
70 Correct 374 ms 60132 KB Output is correct