답안 #1053379

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053379 2024-08-11T11:13:00 Z vincentbucourt1 경주 (Race) (IOI11_race) C++14
43 / 100
179 ms 85820 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 = (ll) N;
	sumNeed = (ll) K;

	if (sumNeed == 1) return 0;
	
	for (int i = 0; i < N-1; i++) {
		adj[H[i][0]].push_back({(ll) H[i][1], (ll) L[i]});
		adj[H[i][1]].push_back({(ll) H[i][0], (ll) L[i]});
	}

	dfs();

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

# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21080 KB Output is correct
2 Correct 2 ms 21080 KB Output is correct
3 Correct 2 ms 21340 KB Output is correct
4 Correct 2 ms 21084 KB Output is correct
5 Correct 2 ms 21084 KB Output is correct
6 Correct 3 ms 21296 KB Output is correct
7 Correct 2 ms 21300 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 3 ms 21592 KB Output is correct
12 Correct 2 ms 21080 KB Output is correct
13 Correct 2 ms 21336 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 3 ms 21340 KB Output is correct
18 Correct 2 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21080 KB Output is correct
2 Correct 2 ms 21080 KB Output is correct
3 Correct 2 ms 21340 KB Output is correct
4 Correct 2 ms 21084 KB Output is correct
5 Correct 2 ms 21084 KB Output is correct
6 Correct 3 ms 21296 KB Output is correct
7 Correct 2 ms 21300 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 3 ms 21592 KB Output is correct
12 Correct 2 ms 21080 KB Output is correct
13 Correct 2 ms 21336 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 3 ms 21340 KB Output is correct
18 Correct 2 ms 21084 KB Output is correct
19 Correct 2 ms 21084 KB Output is correct
20 Correct 3 ms 21084 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 21340 KB Output is correct
28 Correct 3 ms 21364 KB Output is correct
29 Correct 3 ms 21340 KB Output is correct
30 Correct 3 ms 21272 KB Output is correct
31 Correct 3 ms 21340 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 3 ms 21312 KB Output is correct
37 Correct 2 ms 21432 KB Output is correct
38 Correct 3 ms 21336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21080 KB Output is correct
2 Correct 2 ms 21080 KB Output is correct
3 Correct 2 ms 21340 KB Output is correct
4 Correct 2 ms 21084 KB Output is correct
5 Correct 2 ms 21084 KB Output is correct
6 Correct 3 ms 21296 KB Output is correct
7 Correct 2 ms 21300 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 3 ms 21592 KB Output is correct
12 Correct 2 ms 21080 KB Output is correct
13 Correct 2 ms 21336 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 3 ms 21340 KB Output is correct
18 Correct 2 ms 21084 KB Output is correct
19 Correct 47 ms 30036 KB Output is correct
20 Correct 51 ms 30036 KB Output is correct
21 Correct 57 ms 30028 KB Output is correct
22 Correct 49 ms 30068 KB Output is correct
23 Correct 66 ms 30544 KB Output is correct
24 Correct 54 ms 29704 KB Output is correct
25 Correct 46 ms 42844 KB Output is correct
26 Correct 38 ms 54620 KB Output is correct
27 Correct 93 ms 37456 KB Output is correct
28 Correct 169 ms 85820 KB Output is correct
29 Correct 179 ms 83952 KB Output is correct
30 Correct 96 ms 37436 KB Output is correct
31 Correct 90 ms 37460 KB Output is correct
32 Correct 99 ms 37564 KB Output is correct
33 Correct 99 ms 36692 KB Output is correct
34 Correct 171 ms 50264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 21080 KB Output is correct
2 Correct 2 ms 21080 KB Output is correct
3 Correct 2 ms 21340 KB Output is correct
4 Correct 2 ms 21084 KB Output is correct
5 Correct 2 ms 21084 KB Output is correct
6 Correct 3 ms 21296 KB Output is correct
7 Correct 2 ms 21300 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 3 ms 21592 KB Output is correct
12 Correct 2 ms 21080 KB Output is correct
13 Correct 2 ms 21336 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 3 ms 21340 KB Output is correct
18 Correct 2 ms 21084 KB Output is correct
19 Correct 2 ms 21084 KB Output is correct
20 Correct 3 ms 21084 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 21340 KB Output is correct
28 Correct 3 ms 21364 KB Output is correct
29 Correct 3 ms 21340 KB Output is correct
30 Correct 3 ms 21272 KB Output is correct
31 Correct 3 ms 21340 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 3 ms 21312 KB Output is correct
37 Correct 2 ms 21432 KB Output is correct
38 Correct 3 ms 21336 KB Output is correct
39 Correct 47 ms 30036 KB Output is correct
40 Correct 51 ms 30036 KB Output is correct
41 Correct 57 ms 30028 KB Output is correct
42 Correct 49 ms 30068 KB Output is correct
43 Correct 66 ms 30544 KB Output is correct
44 Correct 54 ms 29704 KB Output is correct
45 Correct 46 ms 42844 KB Output is correct
46 Correct 38 ms 54620 KB Output is correct
47 Correct 93 ms 37456 KB Output is correct
48 Correct 169 ms 85820 KB Output is correct
49 Correct 179 ms 83952 KB Output is correct
50 Correct 96 ms 37436 KB Output is correct
51 Correct 90 ms 37460 KB Output is correct
52 Correct 99 ms 37564 KB Output is correct
53 Correct 99 ms 36692 KB Output is correct
54 Correct 171 ms 50264 KB Output is correct
55 Correct 9 ms 22360 KB Output is correct
56 Correct 5 ms 21852 KB Output is correct
57 Incorrect 31 ms 30264 KB Output isn't correct
58 Halted 0 ms 0 KB -