답안 #787799

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
787799 2023-07-19T12:49:52 Z allin27x 경주 (Race) (IOI11_race) C++17
100 / 100
540 ms 136840 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n; int t;
signed ans = 1e7;
unordered_map<int,int> adj[(int)2e5];
int off1[(int)2e5];
int off2[(int)2e5];
unordered_map<int, int> pth[(int)2e5];

void dfs(int i, int p){
	for (auto const &pair1: adj[i]){
		int c = pair1.first; int w = pair1.second;
		if (c==p) continue;
		dfs(c,i);
		off1[c]+=w;
		off2[c]+=1;
		if (pth[i].size() < pth[c].size()){
			swap(pth[i], pth[c]);
			swap(off1[c], off1[i]);
			swap(off2[c], off2[i]);
		}
		for (auto const & pr: pth[c]){
			int s = pr.first; int l = pr.second;
			if (pth[i].count(t-s-off1[c]-off1[i])) ans = min(ans,(signed)(l+pth[i][t-s-off1[c]-off1[i]]+off2[i]+off2[c]));
		}

		for (auto const & pr: pth[c]){
			int s = pr.first; int l = pr.second;
			if (pth[i].count(s-off1[i]+off1[c]))pth[i][s-off1[i]+off1[c]] = min(pth[i][s-off1[i]+off1[c]], l+off2[c]-off2[i]);
			else pth[i][s-off1[i]+off1[c]] = l+off2[c]-off2[i];			
		}
	}
}

signed best_path(signed sz, signed k, signed h[][2], signed l[]){
	n = sz; t=k;
	for (int i=0; i<n-1; i++){
		int a = h[i][0]; int b = h[i][1];
		adj[a][b] = l[i]; adj[b][a] = l[i];
	}
	for (int i=0; i<n; i++) pth[i][0] = 0;
	for (int i=0; i<n; i++) off1[i] = 0;
	for (int i=0; i<n; i++) off2[i] = 0;		
	dfs(0,0);
	if (ans==(int)1e7) return -1;
	return ans;
}

// signed main(){
// 	signed n= 11, k=12;
// 	signed h[n-1][2];
// 	signed l[n-1];
// 	for (int i=0; i<n-1; i++) cin>>h[i][0]>>h[i][1];
// 	for (int i=0; i<n-1; i++) cin>>l[i];
// 	cout<<best_path(n, k, h, l);
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 22228 KB Output is correct
2 Correct 13 ms 22260 KB Output is correct
3 Correct 12 ms 22228 KB Output is correct
4 Correct 13 ms 22196 KB Output is correct
5 Correct 11 ms 22244 KB Output is correct
6 Correct 11 ms 22244 KB Output is correct
7 Correct 12 ms 22228 KB Output is correct
8 Correct 13 ms 22248 KB Output is correct
9 Correct 12 ms 22192 KB Output is correct
10 Correct 14 ms 22296 KB Output is correct
11 Correct 12 ms 22228 KB Output is correct
12 Correct 13 ms 22200 KB Output is correct
13 Correct 12 ms 22228 KB Output is correct
14 Correct 11 ms 22228 KB Output is correct
15 Correct 11 ms 22236 KB Output is correct
16 Correct 13 ms 22228 KB Output is correct
17 Correct 14 ms 22216 KB Output is correct
18 Correct 13 ms 22296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 22228 KB Output is correct
2 Correct 13 ms 22260 KB Output is correct
3 Correct 12 ms 22228 KB Output is correct
4 Correct 13 ms 22196 KB Output is correct
5 Correct 11 ms 22244 KB Output is correct
6 Correct 11 ms 22244 KB Output is correct
7 Correct 12 ms 22228 KB Output is correct
8 Correct 13 ms 22248 KB Output is correct
9 Correct 12 ms 22192 KB Output is correct
10 Correct 14 ms 22296 KB Output is correct
11 Correct 12 ms 22228 KB Output is correct
12 Correct 13 ms 22200 KB Output is correct
13 Correct 12 ms 22228 KB Output is correct
14 Correct 11 ms 22228 KB Output is correct
15 Correct 11 ms 22236 KB Output is correct
16 Correct 13 ms 22228 KB Output is correct
17 Correct 14 ms 22216 KB Output is correct
18 Correct 13 ms 22296 KB Output is correct
19 Correct 11 ms 22188 KB Output is correct
20 Correct 11 ms 22228 KB Output is correct
21 Correct 12 ms 22684 KB Output is correct
22 Correct 12 ms 22608 KB Output is correct
23 Correct 12 ms 22704 KB Output is correct
24 Correct 12 ms 22716 KB Output is correct
25 Correct 12 ms 22612 KB Output is correct
26 Correct 13 ms 22612 KB Output is correct
27 Correct 12 ms 22612 KB Output is correct
28 Correct 13 ms 22712 KB Output is correct
29 Correct 13 ms 22720 KB Output is correct
30 Correct 14 ms 22716 KB Output is correct
31 Correct 14 ms 22732 KB Output is correct
32 Correct 13 ms 22612 KB Output is correct
33 Correct 15 ms 22604 KB Output is correct
34 Correct 13 ms 22676 KB Output is correct
35 Correct 13 ms 22628 KB Output is correct
36 Correct 14 ms 22640 KB Output is correct
37 Correct 15 ms 22612 KB Output is correct
38 Correct 15 ms 22552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 22228 KB Output is correct
2 Correct 13 ms 22260 KB Output is correct
3 Correct 12 ms 22228 KB Output is correct
4 Correct 13 ms 22196 KB Output is correct
5 Correct 11 ms 22244 KB Output is correct
6 Correct 11 ms 22244 KB Output is correct
7 Correct 12 ms 22228 KB Output is correct
8 Correct 13 ms 22248 KB Output is correct
9 Correct 12 ms 22192 KB Output is correct
10 Correct 14 ms 22296 KB Output is correct
11 Correct 12 ms 22228 KB Output is correct
12 Correct 13 ms 22200 KB Output is correct
13 Correct 12 ms 22228 KB Output is correct
14 Correct 11 ms 22228 KB Output is correct
15 Correct 11 ms 22236 KB Output is correct
16 Correct 13 ms 22228 KB Output is correct
17 Correct 14 ms 22216 KB Output is correct
18 Correct 13 ms 22296 KB Output is correct
19 Correct 139 ms 62028 KB Output is correct
20 Correct 139 ms 62048 KB Output is correct
21 Correct 138 ms 62020 KB Output is correct
22 Correct 214 ms 62464 KB Output is correct
23 Correct 163 ms 69456 KB Output is correct
24 Correct 137 ms 63500 KB Output is correct
25 Correct 142 ms 65808 KB Output is correct
26 Correct 92 ms 73420 KB Output is correct
27 Correct 273 ms 95820 KB Output is correct
28 Correct 333 ms 134060 KB Output is correct
29 Correct 357 ms 131740 KB Output is correct
30 Correct 267 ms 95820 KB Output is correct
31 Correct 292 ms 95804 KB Output is correct
32 Correct 458 ms 95800 KB Output is correct
33 Correct 317 ms 99104 KB Output is correct
34 Correct 465 ms 121508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 22228 KB Output is correct
2 Correct 13 ms 22260 KB Output is correct
3 Correct 12 ms 22228 KB Output is correct
4 Correct 13 ms 22196 KB Output is correct
5 Correct 11 ms 22244 KB Output is correct
6 Correct 11 ms 22244 KB Output is correct
7 Correct 12 ms 22228 KB Output is correct
8 Correct 13 ms 22248 KB Output is correct
9 Correct 12 ms 22192 KB Output is correct
10 Correct 14 ms 22296 KB Output is correct
11 Correct 12 ms 22228 KB Output is correct
12 Correct 13 ms 22200 KB Output is correct
13 Correct 12 ms 22228 KB Output is correct
14 Correct 11 ms 22228 KB Output is correct
15 Correct 11 ms 22236 KB Output is correct
16 Correct 13 ms 22228 KB Output is correct
17 Correct 14 ms 22216 KB Output is correct
18 Correct 13 ms 22296 KB Output is correct
19 Correct 11 ms 22188 KB Output is correct
20 Correct 11 ms 22228 KB Output is correct
21 Correct 12 ms 22684 KB Output is correct
22 Correct 12 ms 22608 KB Output is correct
23 Correct 12 ms 22704 KB Output is correct
24 Correct 12 ms 22716 KB Output is correct
25 Correct 12 ms 22612 KB Output is correct
26 Correct 13 ms 22612 KB Output is correct
27 Correct 12 ms 22612 KB Output is correct
28 Correct 13 ms 22712 KB Output is correct
29 Correct 13 ms 22720 KB Output is correct
30 Correct 14 ms 22716 KB Output is correct
31 Correct 14 ms 22732 KB Output is correct
32 Correct 13 ms 22612 KB Output is correct
33 Correct 15 ms 22604 KB Output is correct
34 Correct 13 ms 22676 KB Output is correct
35 Correct 13 ms 22628 KB Output is correct
36 Correct 14 ms 22640 KB Output is correct
37 Correct 15 ms 22612 KB Output is correct
38 Correct 15 ms 22552 KB Output is correct
39 Correct 139 ms 62028 KB Output is correct
40 Correct 139 ms 62048 KB Output is correct
41 Correct 138 ms 62020 KB Output is correct
42 Correct 214 ms 62464 KB Output is correct
43 Correct 163 ms 69456 KB Output is correct
44 Correct 137 ms 63500 KB Output is correct
45 Correct 142 ms 65808 KB Output is correct
46 Correct 92 ms 73420 KB Output is correct
47 Correct 273 ms 95820 KB Output is correct
48 Correct 333 ms 134060 KB Output is correct
49 Correct 357 ms 131740 KB Output is correct
50 Correct 267 ms 95820 KB Output is correct
51 Correct 292 ms 95804 KB Output is correct
52 Correct 458 ms 95800 KB Output is correct
53 Correct 317 ms 99104 KB Output is correct
54 Correct 465 ms 121508 KB Output is correct
55 Correct 25 ms 27220 KB Output is correct
56 Correct 24 ms 25952 KB Output is correct
57 Correct 86 ms 59624 KB Output is correct
58 Correct 74 ms 57532 KB Output is correct
59 Correct 89 ms 78068 KB Output is correct
60 Correct 328 ms 132596 KB Output is correct
61 Correct 286 ms 98092 KB Output is correct
62 Correct 332 ms 95692 KB Output is correct
63 Correct 451 ms 95712 KB Output is correct
64 Correct 540 ms 131340 KB Output is correct
65 Correct 525 ms 136840 KB Output is correct
66 Correct 377 ms 128048 KB Output is correct
67 Correct 266 ms 93212 KB Output is correct
68 Correct 507 ms 107792 KB Output is correct
69 Correct 487 ms 107880 KB Output is correct
70 Correct 465 ms 103464 KB Output is correct