답안 #1053366

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053366 2024-08-11T10:59:18 Z vincentbucourt1 경주 (Race) (IOI11_race) C++14
43 / 100
174 ms 82768 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second

const static ll INF = 1e18;
const static ll MAXN = 200001;

static ll N, sumNeed;
static vector<pair<ll, ll>> adj[MAXN];

static ll depth[MAXN], sum[MAXN];
static map<ll, ll> maps[MAXN];
static ll ans = INF;

void dfs (ll node = 0, ll parent = -1) {
	maps[node][sum[node]] = depth[node];
	for (pair<ll, ll> nxt : adj[node]) {
		ll nodenxt = nxt.f, weightnxt = nxt.s;
		if (nodenxt == parent) continue;

		depth[nodenxt] = depth[node] + 1;
		sum[nodenxt] = sum[node] + weightnxt;

		dfs(nodenxt, node);

		if (maps[nodenxt].size() > maps[node].size()) swap(maps[nodenxt], maps[node]);
		for (pair<ll, ll> elem : maps[nodenxt]) {
			ll sumOn = elem.f, depthOn = elem.s;

			ll need = -sumOn + 2*sum[node] + sumNeed;
			if (maps[node].find(need) != maps[node].end()) {
				ans = min(ans, maps[node][need] - 2*depth[node] + depthOn);
			}

			if (maps[node].find(sumOn) == maps[node].end()) {
				maps[node][sumOn] = depthOn;
			}
			else {
				maps[node][sumOn] = min(maps[node][sumOn], depthOn);
			}
		}
		maps[nodenxt].clear();
	}
}

int best_path(int N, int K, int H[][2], int L[])
{
	::N = N;
	sumNeed = K;
	for (int i = 0; i < N-1; i++) {
		adj[H[i][0]].push_back({H[i][1], L[i]});
		adj[H[i][1]].push_back({H[i][0], L[i]});
	}

	dfs();

	if (ans == INF) return -1;
	else return (int) ans;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21084 KB Output is correct
2 Correct 2 ms 21084 KB Output is correct
3 Correct 2 ms 21084 KB Output is correct
4 Correct 2 ms 21084 KB Output is correct
5 Correct 2 ms 21084 KB Output is correct
6 Correct 2 ms 21084 KB Output is correct
7 Correct 2 ms 21084 KB Output is correct
8 Correct 2 ms 21084 KB Output is correct
9 Correct 2 ms 21084 KB Output is correct
10 Correct 2 ms 21084 KB Output is correct
11 Correct 2 ms 21288 KB Output is correct
12 Correct 2 ms 21084 KB Output is correct
13 Correct 3 ms 21084 KB Output is correct
14 Correct 2 ms 21084 KB Output is correct
15 Correct 2 ms 21084 KB Output is correct
16 Correct 2 ms 21084 KB Output is correct
17 Correct 2 ms 21084 KB Output is correct
18 Correct 3 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21084 KB Output is correct
2 Correct 2 ms 21084 KB Output is correct
3 Correct 2 ms 21084 KB Output is correct
4 Correct 2 ms 21084 KB Output is correct
5 Correct 2 ms 21084 KB Output is correct
6 Correct 2 ms 21084 KB Output is correct
7 Correct 2 ms 21084 KB Output is correct
8 Correct 2 ms 21084 KB Output is correct
9 Correct 2 ms 21084 KB Output is correct
10 Correct 2 ms 21084 KB Output is correct
11 Correct 2 ms 21288 KB Output is correct
12 Correct 2 ms 21084 KB Output is correct
13 Correct 3 ms 21084 KB Output is correct
14 Correct 2 ms 21084 KB Output is correct
15 Correct 2 ms 21084 KB Output is correct
16 Correct 2 ms 21084 KB Output is correct
17 Correct 2 ms 21084 KB Output is correct
18 Correct 3 ms 21084 KB Output is correct
19 Correct 2 ms 21084 KB Output is correct
20 Correct 2 ms 21080 KB Output is correct
21 Correct 3 ms 21340 KB Output is correct
22 Correct 3 ms 21340 KB Output is correct
23 Correct 3 ms 21340 KB Output is correct
24 Correct 3 ms 21340 KB Output is correct
25 Correct 3 ms 21340 KB Output is correct
26 Correct 3 ms 21340 KB Output is correct
27 Correct 3 ms 21336 KB Output is correct
28 Correct 3 ms 21340 KB Output is correct
29 Correct 3 ms 21376 KB Output is correct
30 Correct 3 ms 21340 KB Output is correct
31 Correct 3 ms 21368 KB Output is correct
32 Correct 3 ms 21340 KB Output is correct
33 Correct 3 ms 21340 KB Output is correct
34 Correct 3 ms 21340 KB Output is correct
35 Correct 2 ms 21340 KB Output is correct
36 Correct 2 ms 21340 KB Output is correct
37 Correct 3 ms 21340 KB Output is correct
38 Correct 3 ms 21296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21084 KB Output is correct
2 Correct 2 ms 21084 KB Output is correct
3 Correct 2 ms 21084 KB Output is correct
4 Correct 2 ms 21084 KB Output is correct
5 Correct 2 ms 21084 KB Output is correct
6 Correct 2 ms 21084 KB Output is correct
7 Correct 2 ms 21084 KB Output is correct
8 Correct 2 ms 21084 KB Output is correct
9 Correct 2 ms 21084 KB Output is correct
10 Correct 2 ms 21084 KB Output is correct
11 Correct 2 ms 21288 KB Output is correct
12 Correct 2 ms 21084 KB Output is correct
13 Correct 3 ms 21084 KB Output is correct
14 Correct 2 ms 21084 KB Output is correct
15 Correct 2 ms 21084 KB Output is correct
16 Correct 2 ms 21084 KB Output is correct
17 Correct 2 ms 21084 KB Output is correct
18 Correct 3 ms 21084 KB Output is correct
19 Correct 54 ms 28496 KB Output is correct
20 Correct 48 ms 28704 KB Output is correct
21 Correct 49 ms 28504 KB Output is correct
22 Correct 56 ms 28504 KB Output is correct
23 Correct 72 ms 29084 KB Output is correct
24 Correct 49 ms 28248 KB Output is correct
25 Correct 46 ms 41556 KB Output is correct
26 Correct 39 ms 53192 KB Output is correct
27 Correct 98 ms 34524 KB Output is correct
28 Correct 155 ms 82768 KB Output is correct
29 Correct 174 ms 80808 KB Output is correct
30 Correct 89 ms 34516 KB Output is correct
31 Correct 92 ms 34384 KB Output is correct
32 Correct 96 ms 34448 KB Output is correct
33 Correct 102 ms 33876 KB Output is correct
34 Correct 174 ms 46416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21084 KB Output is correct
2 Correct 2 ms 21084 KB Output is correct
3 Correct 2 ms 21084 KB Output is correct
4 Correct 2 ms 21084 KB Output is correct
5 Correct 2 ms 21084 KB Output is correct
6 Correct 2 ms 21084 KB Output is correct
7 Correct 2 ms 21084 KB Output is correct
8 Correct 2 ms 21084 KB Output is correct
9 Correct 2 ms 21084 KB Output is correct
10 Correct 2 ms 21084 KB Output is correct
11 Correct 2 ms 21288 KB Output is correct
12 Correct 2 ms 21084 KB Output is correct
13 Correct 3 ms 21084 KB Output is correct
14 Correct 2 ms 21084 KB Output is correct
15 Correct 2 ms 21084 KB Output is correct
16 Correct 2 ms 21084 KB Output is correct
17 Correct 2 ms 21084 KB Output is correct
18 Correct 3 ms 21084 KB Output is correct
19 Correct 2 ms 21084 KB Output is correct
20 Correct 2 ms 21080 KB Output is correct
21 Correct 3 ms 21340 KB Output is correct
22 Correct 3 ms 21340 KB Output is correct
23 Correct 3 ms 21340 KB Output is correct
24 Correct 3 ms 21340 KB Output is correct
25 Correct 3 ms 21340 KB Output is correct
26 Correct 3 ms 21340 KB Output is correct
27 Correct 3 ms 21336 KB Output is correct
28 Correct 3 ms 21340 KB Output is correct
29 Correct 3 ms 21376 KB Output is correct
30 Correct 3 ms 21340 KB Output is correct
31 Correct 3 ms 21368 KB Output is correct
32 Correct 3 ms 21340 KB Output is correct
33 Correct 3 ms 21340 KB Output is correct
34 Correct 3 ms 21340 KB Output is correct
35 Correct 2 ms 21340 KB Output is correct
36 Correct 2 ms 21340 KB Output is correct
37 Correct 3 ms 21340 KB Output is correct
38 Correct 3 ms 21296 KB Output is correct
39 Correct 54 ms 28496 KB Output is correct
40 Correct 48 ms 28704 KB Output is correct
41 Correct 49 ms 28504 KB Output is correct
42 Correct 56 ms 28504 KB Output is correct
43 Correct 72 ms 29084 KB Output is correct
44 Correct 49 ms 28248 KB Output is correct
45 Correct 46 ms 41556 KB Output is correct
46 Correct 39 ms 53192 KB Output is correct
47 Correct 98 ms 34524 KB Output is correct
48 Correct 155 ms 82768 KB Output is correct
49 Correct 174 ms 80808 KB Output is correct
50 Correct 89 ms 34516 KB Output is correct
51 Correct 92 ms 34384 KB Output is correct
52 Correct 96 ms 34448 KB Output is correct
53 Correct 102 ms 33876 KB Output is correct
54 Correct 174 ms 46416 KB Output is correct
55 Correct 9 ms 22108 KB Output is correct
56 Correct 5 ms 21852 KB Output is correct
57 Incorrect 29 ms 28924 KB Output isn't correct
58 Halted 0 ms 0 KB -