# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
398261 |
2021-05-04T03:25:06 Z |
JerryLiu06 |
Race (IOI11_race) |
C++11 |
|
529 ms |
35204 KB |
#include <bits/stdc++.h>
#include"race.h"
using namespace std;
using ll = long long;
using db = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define mp make_pair
#define f first
#define s second
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)
const int MOD = 1e9 + 7;
const int MX = 2e5 + 10;
const ll INF = 1e18;
int N, K, timer, ans = MOD; vpi adj[MX]; int sub[MX]; bool vis[MX]; pi cur[1000010];
void DFS1(int X, int P) {
sub[X] = 1; EACH(Y, adj[X]) if (Y.f != P && !vis[Y.f]) { DFS1(Y.f, X); sub[X] += sub[Y.f]; }
}
int getCent(int X, int P, int S) {
EACH(Y, adj[X]) if (Y.f != P && !vis[Y.f] && sub[Y.f] > S / 2) return getCent(Y.f, X, S); return X;
}
void DFS2(int X, int P, bool upd, int dist, int depth) {
if (dist > K) return ;
if (upd) { if (cur[dist].f == timer) cur[dist].s = min(cur[dist].s, depth); else cur[dist] = {timer, depth}; }
else { if (cur[K - dist].f == timer) ans = min(ans, cur[K - dist].s + depth); }
EACH(Y, adj[X]) if (Y.f != P && !vis[Y.f]) DFS2(Y.f, X, upd, dist + Y.s, depth + 1);
}
void decomp(int X) {
DFS1(X, -1); int C = getCent(X, -1, sub[X]); vis[C] = true; cur[0] = {++timer, 0};
EACH(Y, adj[C]) if (!vis[Y.f]) { DFS2(Y.f, C, false, Y.s, 1); DFS2(Y.f, C, true, Y.s, 1); }
EACH(Y, adj[C]) if (!vis[Y.f]) decomp(Y.f);
}
int best_path(int _N, int _K, int H[][2], int L[]) {
N = _N; K = _K; F0R(i, N - 1) {
int A = H[i][0]; int B = H[i][1];
adj[A].pb({B, L[i]}), adj[B].pb({A, L[i]});
}
decomp(0); return (ans == MOD ? -1 : ans);
}
Compilation message
race.cpp: In function 'int getCent(int, int, int)':
race.cpp:42:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
42 | #define EACH(a, x) for (auto& a : x)
| ^~~
race.cpp:54:5: note: in expansion of macro 'EACH'
54 | EACH(Y, adj[X]) if (Y.f != P && !vis[Y.f] && sub[Y.f] > S / 2) return getCent(Y.f, X, S); return X;
| ^~~~
race.cpp:54:95: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
54 | EACH(Y, adj[X]) if (Y.f != P && !vis[Y.f] && sub[Y.f] > S / 2) return getCent(Y.f, X, S); return X;
| ^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4944 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
4 ms |
4940 KB |
Output is correct |
10 |
Correct |
4 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
4 ms |
5000 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
5004 KB |
Output is correct |
17 |
Correct |
4 ms |
5000 KB |
Output is correct |
18 |
Correct |
4 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4944 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
4 ms |
4940 KB |
Output is correct |
10 |
Correct |
4 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
4 ms |
5000 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
5004 KB |
Output is correct |
17 |
Correct |
4 ms |
5000 KB |
Output is correct |
18 |
Correct |
4 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4944 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
4 ms |
5068 KB |
Output is correct |
22 |
Correct |
7 ms |
8396 KB |
Output is correct |
23 |
Correct |
6 ms |
7956 KB |
Output is correct |
24 |
Correct |
7 ms |
9164 KB |
Output is correct |
25 |
Correct |
7 ms |
8212 KB |
Output is correct |
26 |
Correct |
6 ms |
7372 KB |
Output is correct |
27 |
Correct |
6 ms |
5012 KB |
Output is correct |
28 |
Correct |
7 ms |
6612 KB |
Output is correct |
29 |
Correct |
6 ms |
7500 KB |
Output is correct |
30 |
Correct |
6 ms |
7700 KB |
Output is correct |
31 |
Correct |
7 ms |
8396 KB |
Output is correct |
32 |
Correct |
7 ms |
8396 KB |
Output is correct |
33 |
Correct |
8 ms |
9804 KB |
Output is correct |
34 |
Correct |
7 ms |
9036 KB |
Output is correct |
35 |
Correct |
9 ms |
10060 KB |
Output is correct |
36 |
Correct |
9 ms |
10316 KB |
Output is correct |
37 |
Correct |
7 ms |
8268 KB |
Output is correct |
38 |
Correct |
6 ms |
7244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4944 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
4 ms |
4940 KB |
Output is correct |
10 |
Correct |
4 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
4 ms |
5000 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
5004 KB |
Output is correct |
17 |
Correct |
4 ms |
5000 KB |
Output is correct |
18 |
Correct |
4 ms |
4940 KB |
Output is correct |
19 |
Correct |
150 ms |
11708 KB |
Output is correct |
20 |
Correct |
135 ms |
11660 KB |
Output is correct |
21 |
Correct |
177 ms |
11728 KB |
Output is correct |
22 |
Correct |
131 ms |
11792 KB |
Output is correct |
23 |
Correct |
81 ms |
12024 KB |
Output is correct |
24 |
Correct |
81 ms |
11912 KB |
Output is correct |
25 |
Correct |
139 ms |
14536 KB |
Output is correct |
26 |
Correct |
96 ms |
17304 KB |
Output is correct |
27 |
Correct |
216 ms |
18764 KB |
Output is correct |
28 |
Correct |
314 ms |
30204 KB |
Output is correct |
29 |
Correct |
333 ms |
29124 KB |
Output is correct |
30 |
Correct |
181 ms |
18756 KB |
Output is correct |
31 |
Correct |
189 ms |
18672 KB |
Output is correct |
32 |
Correct |
249 ms |
18884 KB |
Output is correct |
33 |
Correct |
223 ms |
17600 KB |
Output is correct |
34 |
Correct |
193 ms |
18440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
4 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
4 ms |
4940 KB |
Output is correct |
6 |
Correct |
4 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4944 KB |
Output is correct |
8 |
Correct |
4 ms |
4940 KB |
Output is correct |
9 |
Correct |
4 ms |
4940 KB |
Output is correct |
10 |
Correct |
4 ms |
4940 KB |
Output is correct |
11 |
Correct |
4 ms |
4940 KB |
Output is correct |
12 |
Correct |
4 ms |
5000 KB |
Output is correct |
13 |
Correct |
4 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
3 ms |
5004 KB |
Output is correct |
17 |
Correct |
4 ms |
5000 KB |
Output is correct |
18 |
Correct |
4 ms |
4940 KB |
Output is correct |
19 |
Correct |
3 ms |
4944 KB |
Output is correct |
20 |
Correct |
3 ms |
4940 KB |
Output is correct |
21 |
Correct |
4 ms |
5068 KB |
Output is correct |
22 |
Correct |
7 ms |
8396 KB |
Output is correct |
23 |
Correct |
6 ms |
7956 KB |
Output is correct |
24 |
Correct |
7 ms |
9164 KB |
Output is correct |
25 |
Correct |
7 ms |
8212 KB |
Output is correct |
26 |
Correct |
6 ms |
7372 KB |
Output is correct |
27 |
Correct |
6 ms |
5012 KB |
Output is correct |
28 |
Correct |
7 ms |
6612 KB |
Output is correct |
29 |
Correct |
6 ms |
7500 KB |
Output is correct |
30 |
Correct |
6 ms |
7700 KB |
Output is correct |
31 |
Correct |
7 ms |
8396 KB |
Output is correct |
32 |
Correct |
7 ms |
8396 KB |
Output is correct |
33 |
Correct |
8 ms |
9804 KB |
Output is correct |
34 |
Correct |
7 ms |
9036 KB |
Output is correct |
35 |
Correct |
9 ms |
10060 KB |
Output is correct |
36 |
Correct |
9 ms |
10316 KB |
Output is correct |
37 |
Correct |
7 ms |
8268 KB |
Output is correct |
38 |
Correct |
6 ms |
7244 KB |
Output is correct |
39 |
Correct |
150 ms |
11708 KB |
Output is correct |
40 |
Correct |
135 ms |
11660 KB |
Output is correct |
41 |
Correct |
177 ms |
11728 KB |
Output is correct |
42 |
Correct |
131 ms |
11792 KB |
Output is correct |
43 |
Correct |
81 ms |
12024 KB |
Output is correct |
44 |
Correct |
81 ms |
11912 KB |
Output is correct |
45 |
Correct |
139 ms |
14536 KB |
Output is correct |
46 |
Correct |
96 ms |
17304 KB |
Output is correct |
47 |
Correct |
216 ms |
18764 KB |
Output is correct |
48 |
Correct |
314 ms |
30204 KB |
Output is correct |
49 |
Correct |
333 ms |
29124 KB |
Output is correct |
50 |
Correct |
181 ms |
18756 KB |
Output is correct |
51 |
Correct |
189 ms |
18672 KB |
Output is correct |
52 |
Correct |
249 ms |
18884 KB |
Output is correct |
53 |
Correct |
223 ms |
17600 KB |
Output is correct |
54 |
Correct |
193 ms |
18440 KB |
Output is correct |
55 |
Correct |
12 ms |
5736 KB |
Output is correct |
56 |
Correct |
16 ms |
5580 KB |
Output is correct |
57 |
Correct |
85 ms |
11872 KB |
Output is correct |
58 |
Correct |
42 ms |
11592 KB |
Output is correct |
59 |
Correct |
100 ms |
18144 KB |
Output is correct |
60 |
Correct |
474 ms |
34092 KB |
Output is correct |
61 |
Correct |
200 ms |
18980 KB |
Output is correct |
62 |
Correct |
253 ms |
19040 KB |
Output is correct |
63 |
Correct |
278 ms |
18936 KB |
Output is correct |
64 |
Correct |
529 ms |
21284 KB |
Output is correct |
65 |
Correct |
246 ms |
19676 KB |
Output is correct |
66 |
Correct |
415 ms |
35204 KB |
Output is correct |
67 |
Correct |
122 ms |
19508 KB |
Output is correct |
68 |
Correct |
296 ms |
24872 KB |
Output is correct |
69 |
Correct |
290 ms |
25208 KB |
Output is correct |
70 |
Correct |
270 ms |
24308 KB |
Output is correct |