Submission #551214

# Submission time Handle Problem Language Result Execution time Memory
551214 2022-04-20T05:54:16 Z alireza_kaviani Race (IOI11_race) C++17
100 / 100
739 ms 159948 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std;

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

#define X     first
#define Y     second
#define SZ(x) ll((x).size())

const ll MAXN = 2e5 + 10;
const ll INF = 1e18;

ll n , k , ans = INF , H[MAXN] , dist[MAXN];
vector<pii> adj[MAXN];
map<ll , ll> mn[MAXN];

void DFS(int v , int p = -1){
	for(pii i : adj[v]){
		int u = i.X , w = i.Y;
		if(u == p)	continue;
		H[u] = H[v] + 1;
		dist[u] = dist[v] + w;
		DFS(u , v);
		if(SZ(mn[u]) > SZ(mn[v])){
			mn[v].swap(mn[u]);
		}
		for(auto &i : mn[u]){
			if(i.Y == 0)	continue;
			ll D = k + dist[v] * 2 - i.X;
			if(mn[v][D] != 0){
				ans = min(ans , i.Y + mn[v][D] - 2 * H[v]);
			}
		}
		for(auto &i : mn[u]){
			if(i.Y == 0)	continue;
			if(mn[v][i.X] == 0)	mn[v][i.X] = i.Y;
			mn[v][i.X] = min(mn[v][i.X] , i.Y);
		}
	}
	ll D = k + dist[v];
	if(mn[v][D] != 0){
		ans = min(ans , mn[v][D] - H[v]);
	}
	if(mn[v][dist[v]] == 0)	mn[v][dist[v]] = H[v];
	mn[v][dist[v]] = min(mn[v][dist[v]] , H[v]);
}

int best_path(int N, int K, int H[][2], int L[]){
	n = N; k = K;
	for(int i = 0 ; i + 1 < n ; i++){
		int v = H[i][0] , u = H[i][1] , w = L[i];
		adj[v].push_back({u , w});
		adj[u].push_back({v , w});
	}
	DFS(0);
	return (ans == INF ? -1 : ans);
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 7 ms 14396 KB Output is correct
3 Correct 9 ms 14420 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 14408 KB Output is correct
7 Correct 8 ms 14408 KB Output is correct
8 Correct 10 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 10 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14444 KB Output is correct
16 Correct 7 ms 14420 KB Output is correct
17 Correct 7 ms 14380 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 7 ms 14396 KB Output is correct
3 Correct 9 ms 14420 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 14408 KB Output is correct
7 Correct 8 ms 14408 KB Output is correct
8 Correct 10 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 10 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14444 KB Output is correct
16 Correct 7 ms 14420 KB Output is correct
17 Correct 7 ms 14380 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 8 ms 14420 KB Output is correct
20 Correct 7 ms 14420 KB Output is correct
21 Correct 9 ms 14768 KB Output is correct
22 Correct 12 ms 14804 KB Output is correct
23 Correct 11 ms 14804 KB Output is correct
24 Correct 10 ms 14800 KB Output is correct
25 Correct 10 ms 14804 KB Output is correct
26 Correct 9 ms 14884 KB Output is correct
27 Correct 8 ms 14548 KB Output is correct
28 Correct 11 ms 14804 KB Output is correct
29 Correct 9 ms 14804 KB Output is correct
30 Correct 10 ms 14804 KB Output is correct
31 Correct 10 ms 14804 KB Output is correct
32 Correct 9 ms 14836 KB Output is correct
33 Correct 9 ms 14868 KB Output is correct
34 Correct 8 ms 14676 KB Output is correct
35 Correct 8 ms 14676 KB Output is correct
36 Correct 8 ms 14636 KB Output is correct
37 Correct 11 ms 14644 KB Output is correct
38 Correct 9 ms 14676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 7 ms 14396 KB Output is correct
3 Correct 9 ms 14420 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 14408 KB Output is correct
7 Correct 8 ms 14408 KB Output is correct
8 Correct 10 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 10 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14444 KB Output is correct
16 Correct 7 ms 14420 KB Output is correct
17 Correct 7 ms 14380 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 153 ms 43592 KB Output is correct
20 Correct 144 ms 43416 KB Output is correct
21 Correct 172 ms 43724 KB Output is correct
22 Correct 160 ms 43616 KB Output is correct
23 Correct 280 ms 69752 KB Output is correct
24 Correct 207 ms 54240 KB Output is correct
25 Correct 85 ms 29440 KB Output is correct
26 Correct 52 ms 35932 KB Output is correct
27 Correct 220 ms 51964 KB Output is correct
28 Correct 239 ms 82452 KB Output is correct
29 Correct 233 ms 81768 KB Output is correct
30 Correct 238 ms 51900 KB Output is correct
31 Correct 215 ms 51864 KB Output is correct
32 Correct 273 ms 53076 KB Output is correct
33 Correct 251 ms 44428 KB Output is correct
34 Correct 528 ms 115604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14420 KB Output is correct
2 Correct 7 ms 14396 KB Output is correct
3 Correct 9 ms 14420 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 14408 KB Output is correct
7 Correct 8 ms 14408 KB Output is correct
8 Correct 10 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 10 ms 14420 KB Output is correct
12 Correct 7 ms 14420 KB Output is correct
13 Correct 7 ms 14420 KB Output is correct
14 Correct 7 ms 14420 KB Output is correct
15 Correct 7 ms 14444 KB Output is correct
16 Correct 7 ms 14420 KB Output is correct
17 Correct 7 ms 14380 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 8 ms 14420 KB Output is correct
20 Correct 7 ms 14420 KB Output is correct
21 Correct 9 ms 14768 KB Output is correct
22 Correct 12 ms 14804 KB Output is correct
23 Correct 11 ms 14804 KB Output is correct
24 Correct 10 ms 14800 KB Output is correct
25 Correct 10 ms 14804 KB Output is correct
26 Correct 9 ms 14884 KB Output is correct
27 Correct 8 ms 14548 KB Output is correct
28 Correct 11 ms 14804 KB Output is correct
29 Correct 9 ms 14804 KB Output is correct
30 Correct 10 ms 14804 KB Output is correct
31 Correct 10 ms 14804 KB Output is correct
32 Correct 9 ms 14836 KB Output is correct
33 Correct 9 ms 14868 KB Output is correct
34 Correct 8 ms 14676 KB Output is correct
35 Correct 8 ms 14676 KB Output is correct
36 Correct 8 ms 14636 KB Output is correct
37 Correct 11 ms 14644 KB Output is correct
38 Correct 9 ms 14676 KB Output is correct
39 Correct 153 ms 43592 KB Output is correct
40 Correct 144 ms 43416 KB Output is correct
41 Correct 172 ms 43724 KB Output is correct
42 Correct 160 ms 43616 KB Output is correct
43 Correct 280 ms 69752 KB Output is correct
44 Correct 207 ms 54240 KB Output is correct
45 Correct 85 ms 29440 KB Output is correct
46 Correct 52 ms 35932 KB Output is correct
47 Correct 220 ms 51964 KB Output is correct
48 Correct 239 ms 82452 KB Output is correct
49 Correct 233 ms 81768 KB Output is correct
50 Correct 238 ms 51900 KB Output is correct
51 Correct 215 ms 51864 KB Output is correct
52 Correct 273 ms 53076 KB Output is correct
53 Correct 251 ms 44428 KB Output is correct
54 Correct 528 ms 115604 KB Output is correct
55 Correct 29 ms 19172 KB Output is correct
56 Correct 17 ms 16852 KB Output is correct
57 Correct 101 ms 42292 KB Output is correct
58 Correct 64 ms 33480 KB Output is correct
59 Correct 153 ms 48204 KB Output is correct
60 Correct 332 ms 81740 KB Output is correct
61 Correct 279 ms 59336 KB Output is correct
62 Correct 245 ms 53012 KB Output is correct
63 Correct 265 ms 53144 KB Output is correct
64 Correct 721 ms 159948 KB Output is correct
65 Correct 739 ms 156468 KB Output is correct
66 Correct 371 ms 80920 KB Output is correct
67 Correct 200 ms 52856 KB Output is correct
68 Correct 606 ms 89212 KB Output is correct
69 Correct 642 ms 99316 KB Output is correct
70 Correct 519 ms 86356 KB Output is correct