답안 #697728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697728 2023-02-10T22:44:50 Z xuliu 경주 (Race) (IOI11_race) C++17
100 / 100
481 ms 107496 KB
#include <bits/stdc++.h>
#include "race.h"

using namespace std;

#define ll long long 
#define debug if(0)

const int N = 2e5 + 4;
const int inf = 1e9+7;
vector<pair<int, ll>> V[N];
ll dist[N], depth[N], K;
map<ll, int> M[N]; // map [dist, depth]
ll ans = inf;

void dfs(int v, int p=-1) {
	M[v][dist[v]] = depth[v];
	for(auto e : V[v]) {
		int u = e.first; ll w = e.second;
		if(u != p) {
			dist[u] = dist[v]+w;
			depth[u] = depth[v]+1;
			dfs(u, v);
		}
	}
}

void dfs2(int v, int p=-1) {
	for(auto e : V[v]) {
		int u = e.first;
		if(u == p) continue;
		dfs2(u, v);
		if((int) M[v].size() < (int) M[u].size()) swap(M[v], M[u]);
		for(auto it = M[u].begin(); it != M[u].end(); ++it) {
			if(M[v].find((K+2LL*dist[v]-it->first)) != M[v].end()) { ans = min(ans, M[v][(K+2LL*dist[v]-it->first)]+it->second-2*depth[v]); }
		}
		for(auto it = M[u].begin(); it != M[u].end(); ++it) {
			if(M[v].find(it->first) != M[v].end()) M[v][it->first] = min(M[v][it->first], it->second);
			else M[v][it->first] = it->second;
		}
	}
}

int best_path(int n, int k, int h[][2], int l[]) {
	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);
	dfs2(0);
	return (ans == inf ? -1 : (int) ans);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14408 KB Output is correct
4 Correct 7 ms 14420 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 14380 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14424 KB Output is correct
13 Correct 7 ms 14408 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 7 ms 14348 KB Output is correct
16 Correct 10 ms 14420 KB Output is correct
17 Correct 9 ms 14420 KB Output is correct
18 Correct 9 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14408 KB Output is correct
4 Correct 7 ms 14420 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 14380 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14424 KB Output is correct
13 Correct 7 ms 14408 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 7 ms 14348 KB Output is correct
16 Correct 10 ms 14420 KB Output is correct
17 Correct 9 ms 14420 KB Output is correct
18 Correct 9 ms 14420 KB Output is correct
19 Correct 7 ms 14412 KB Output is correct
20 Correct 9 ms 14412 KB Output is correct
21 Correct 8 ms 14680 KB Output is correct
22 Correct 8 ms 14708 KB Output is correct
23 Correct 8 ms 14676 KB Output is correct
24 Correct 9 ms 14688 KB Output is correct
25 Correct 9 ms 14680 KB Output is correct
26 Correct 9 ms 14680 KB Output is correct
27 Correct 10 ms 14548 KB Output is correct
28 Correct 9 ms 14676 KB Output is correct
29 Correct 9 ms 14780 KB Output is correct
30 Correct 8 ms 14680 KB Output is correct
31 Correct 8 ms 14640 KB Output is correct
32 Correct 8 ms 14680 KB Output is correct
33 Correct 8 ms 14740 KB Output is correct
34 Correct 8 ms 14684 KB Output is correct
35 Correct 9 ms 14680 KB Output is correct
36 Correct 8 ms 14676 KB Output is correct
37 Correct 8 ms 14544 KB Output is correct
38 Correct 11 ms 14676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14408 KB Output is correct
4 Correct 7 ms 14420 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 14380 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14424 KB Output is correct
13 Correct 7 ms 14408 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 7 ms 14348 KB Output is correct
16 Correct 10 ms 14420 KB Output is correct
17 Correct 9 ms 14420 KB Output is correct
18 Correct 9 ms 14420 KB Output is correct
19 Correct 145 ms 39220 KB Output is correct
20 Correct 143 ms 39232 KB Output is correct
21 Correct 130 ms 38860 KB Output is correct
22 Correct 135 ms 38464 KB Output is correct
23 Correct 189 ms 51424 KB Output is correct
24 Correct 134 ms 41420 KB Output is correct
25 Correct 115 ms 37544 KB Output is correct
26 Correct 60 ms 43480 KB Output is correct
27 Correct 207 ms 52552 KB Output is correct
28 Correct 310 ms 85440 KB Output is correct
29 Correct 312 ms 84416 KB Output is correct
30 Correct 212 ms 52492 KB Output is correct
31 Correct 208 ms 52492 KB Output is correct
32 Correct 300 ms 52676 KB Output is correct
33 Correct 280 ms 57404 KB Output is correct
34 Correct 371 ms 90060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14408 KB Output is correct
4 Correct 7 ms 14420 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 14380 KB Output is correct
8 Correct 8 ms 14420 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 7 ms 14420 KB Output is correct
12 Correct 8 ms 14424 KB Output is correct
13 Correct 7 ms 14408 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 7 ms 14348 KB Output is correct
16 Correct 10 ms 14420 KB Output is correct
17 Correct 9 ms 14420 KB Output is correct
18 Correct 9 ms 14420 KB Output is correct
19 Correct 7 ms 14412 KB Output is correct
20 Correct 9 ms 14412 KB Output is correct
21 Correct 8 ms 14680 KB Output is correct
22 Correct 8 ms 14708 KB Output is correct
23 Correct 8 ms 14676 KB Output is correct
24 Correct 9 ms 14688 KB Output is correct
25 Correct 9 ms 14680 KB Output is correct
26 Correct 9 ms 14680 KB Output is correct
27 Correct 10 ms 14548 KB Output is correct
28 Correct 9 ms 14676 KB Output is correct
29 Correct 9 ms 14780 KB Output is correct
30 Correct 8 ms 14680 KB Output is correct
31 Correct 8 ms 14640 KB Output is correct
32 Correct 8 ms 14680 KB Output is correct
33 Correct 8 ms 14740 KB Output is correct
34 Correct 8 ms 14684 KB Output is correct
35 Correct 9 ms 14680 KB Output is correct
36 Correct 8 ms 14676 KB Output is correct
37 Correct 8 ms 14544 KB Output is correct
38 Correct 11 ms 14676 KB Output is correct
39 Correct 145 ms 39220 KB Output is correct
40 Correct 143 ms 39232 KB Output is correct
41 Correct 130 ms 38860 KB Output is correct
42 Correct 135 ms 38464 KB Output is correct
43 Correct 189 ms 51424 KB Output is correct
44 Correct 134 ms 41420 KB Output is correct
45 Correct 115 ms 37544 KB Output is correct
46 Correct 60 ms 43480 KB Output is correct
47 Correct 207 ms 52552 KB Output is correct
48 Correct 310 ms 85440 KB Output is correct
49 Correct 312 ms 84416 KB Output is correct
50 Correct 212 ms 52492 KB Output is correct
51 Correct 208 ms 52492 KB Output is correct
52 Correct 300 ms 52676 KB Output is correct
53 Correct 280 ms 57404 KB Output is correct
54 Correct 371 ms 90060 KB Output is correct
55 Correct 21 ms 17876 KB Output is correct
56 Correct 15 ms 16480 KB Output is correct
57 Correct 81 ms 36672 KB Output is correct
58 Correct 54 ms 29112 KB Output is correct
59 Correct 91 ms 49744 KB Output is correct
60 Correct 321 ms 84444 KB Output is correct
61 Correct 244 ms 56008 KB Output is correct
62 Correct 203 ms 52596 KB Output is correct
63 Correct 280 ms 52640 KB Output is correct
64 Correct 481 ms 107496 KB Output is correct
65 Correct 465 ms 105320 KB Output is correct
66 Correct 329 ms 81860 KB Output is correct
67 Correct 176 ms 45488 KB Output is correct
68 Correct 398 ms 69032 KB Output is correct
69 Correct 414 ms 73764 KB Output is correct
70 Correct 350 ms 66604 KB Output is correct