Submission #172462

# Submission time Handle Problem Language Result Execution time Memory
172462 2020-01-01T15:10:25 Z cgiosy Race (IOI11_race) C++17
100 / 100
494 ms 38256 KB
#include "race.h"
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<n; i++)
using namespace std;
constexpr int INF=1e9;
 
int best_path(int N, int K, int H[][2], int L[]) {
	int m=INF;
	vector<bool> V(N);
	vector<int> C(N, 1), D(K+1, INF), X;
	vector<pair<int, int>> Y;
	vector<vector<pair<int, int>>> G(N);
	rep(i, 0, N-1) {
		int x=H[i][0], y=H[i][1], z=L[i];
		G[x].push_back({y, z});
		G[y].push_back({x, z});
	}
	#define ITER(i) for(auto[j,w]:G[i]) if(j!=p && !V[j])
	function<void(int, int)> cnt=[&](int i, int p) {
		ITER(i) cnt(j, i), C[i]+=C[j];
	};
	function<int(int, int, int)> cent=[&](int i, int p, int n) {
		ITER(i) if(C[j]>n/2) {
			C[j]+=C[i]-=C[j];
			return cent(j, i, n);
		}
		return i;
	};
	function<void(int, int, int, int)> f=[&](int i, int p, int d, int k) {
		X.push_back(d);
		m=min(m, k+D[K-d]);
		ITER(i) if(d+w<=K && k+1<m) {
			f(j, i, d+w, k+1);
			if(i==p) {
				for(auto[x,y]:Y) D[x]=min(D[x], y);
				Y.clear();
			}
		}
		Y.push_back({d, k});
	};
	function<void(int, int)> cd=[&](int i, int p) {
		V[i=cent(i, p, C[i])]=true, D[0]=0;
		f(i, i, 0, 0);
		for(int x:X) D[x]=INF;
		X.clear();
		ITER(i) cd(j, i);
	};
	cnt(0, 0);
	cd(0, 0);
	return (m==INF?-1:m);
}

Compilation message

race.cpp: In lambda function:
race.cpp:18:30: warning: unused variable 'w' [-Wunused-variable]
  #define ITER(i) for(auto[j,w]:G[i]) if(j!=p && !V[j])
                              ^
race.cpp:20:3: note: in expansion of macro 'ITER'
   ITER(i) cnt(j, i), C[i]+=C[j];
   ^~~~
race.cpp: In lambda function:
race.cpp:18:30: warning: unused variable 'w' [-Wunused-variable]
  #define ITER(i) for(auto[j,w]:G[i]) if(j!=p && !V[j])
                              ^
race.cpp:23:3: note: in expansion of macro 'ITER'
   ITER(i) if(C[j]>n/2) {
   ^~~~
race.cpp: In lambda function:
race.cpp:18:30: warning: unused variable 'w' [-Wunused-variable]
  #define ITER(i) for(auto[j,w]:G[i]) if(j!=p && !V[j])
                              ^
race.cpp:46:3: note: in expansion of macro 'ITER'
   ITER(i) cd(j, i);
   ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 6 ms 4088 KB Output is correct
23 Correct 5 ms 3448 KB Output is correct
24 Correct 6 ms 3832 KB Output is correct
25 Correct 6 ms 3704 KB Output is correct
26 Correct 4 ms 1784 KB Output is correct
27 Correct 5 ms 3576 KB Output is correct
28 Correct 4 ms 1272 KB Output is correct
29 Correct 4 ms 1656 KB Output is correct
30 Correct 4 ms 1912 KB Output is correct
31 Correct 5 ms 3064 KB Output is correct
32 Correct 5 ms 3192 KB Output is correct
33 Correct 6 ms 3576 KB Output is correct
34 Correct 5 ms 2808 KB Output is correct
35 Correct 6 ms 3576 KB Output is correct
36 Correct 4 ms 4088 KB Output is correct
37 Correct 6 ms 3576 KB Output is correct
38 Correct 5 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 121 ms 8284 KB Output is correct
20 Correct 116 ms 8184 KB Output is correct
21 Correct 118 ms 8200 KB Output is correct
22 Correct 134 ms 8568 KB Output is correct
23 Correct 84 ms 9484 KB Output is correct
24 Correct 79 ms 8244 KB Output is correct
25 Correct 171 ms 12524 KB Output is correct
26 Correct 132 ms 17900 KB Output is correct
27 Correct 273 ms 16092 KB Output is correct
28 Correct 318 ms 33528 KB Output is correct
29 Correct 316 ms 31864 KB Output is correct
30 Correct 225 ms 15740 KB Output is correct
31 Correct 220 ms 15736 KB Output is correct
32 Correct 273 ms 15788 KB Output is correct
33 Correct 242 ms 14712 KB Output is correct
34 Correct 239 ms 16852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 6 ms 4088 KB Output is correct
23 Correct 5 ms 3448 KB Output is correct
24 Correct 6 ms 3832 KB Output is correct
25 Correct 6 ms 3704 KB Output is correct
26 Correct 4 ms 1784 KB Output is correct
27 Correct 5 ms 3576 KB Output is correct
28 Correct 4 ms 1272 KB Output is correct
29 Correct 4 ms 1656 KB Output is correct
30 Correct 4 ms 1912 KB Output is correct
31 Correct 5 ms 3064 KB Output is correct
32 Correct 5 ms 3192 KB Output is correct
33 Correct 6 ms 3576 KB Output is correct
34 Correct 5 ms 2808 KB Output is correct
35 Correct 6 ms 3576 KB Output is correct
36 Correct 4 ms 4088 KB Output is correct
37 Correct 6 ms 3576 KB Output is correct
38 Correct 5 ms 2424 KB Output is correct
39 Correct 121 ms 8284 KB Output is correct
40 Correct 116 ms 8184 KB Output is correct
41 Correct 118 ms 8200 KB Output is correct
42 Correct 134 ms 8568 KB Output is correct
43 Correct 84 ms 9484 KB Output is correct
44 Correct 79 ms 8244 KB Output is correct
45 Correct 171 ms 12524 KB Output is correct
46 Correct 132 ms 17900 KB Output is correct
47 Correct 273 ms 16092 KB Output is correct
48 Correct 318 ms 33528 KB Output is correct
49 Correct 316 ms 31864 KB Output is correct
50 Correct 225 ms 15740 KB Output is correct
51 Correct 220 ms 15736 KB Output is correct
52 Correct 273 ms 15788 KB Output is correct
53 Correct 242 ms 14712 KB Output is correct
54 Correct 239 ms 16852 KB Output is correct
55 Correct 11 ms 1144 KB Output is correct
56 Correct 12 ms 1276 KB Output is correct
57 Correct 99 ms 9220 KB Output is correct
58 Correct 55 ms 10476 KB Output is correct
59 Correct 134 ms 18544 KB Output is correct
60 Correct 494 ms 38256 KB Output is correct
61 Correct 231 ms 16120 KB Output is correct
62 Correct 246 ms 20848 KB Output is correct
63 Correct 347 ms 20932 KB Output is correct
64 Correct 461 ms 19516 KB Output is correct
65 Correct 248 ms 15992 KB Output is correct
66 Correct 433 ms 32836 KB Output is correct
67 Correct 185 ms 21768 KB Output is correct
68 Correct 263 ms 19736 KB Output is correct
69 Correct 257 ms 20088 KB Output is correct
70 Correct 231 ms 19128 KB Output is correct