# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
434650 |
2021-06-21T13:50:00 Z |
hhhhaura |
Race (IOI11_race) |
C++14 |
|
1717 ms |
46684 KB |
#define wiwihorz
#include "race.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)
using namespace std;
#define ll long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#ifdef wiwihorz
#define print(a...) cerr << "line " << __LINE__ << ": ", kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else
#define print(...) 0
#define vprint(...) 0
#endif
int n, k, ii, cc;
ll ans;
vector<vector<int>> mp;
vector<int> pre, es, cost, vis;
vector<int> sz, mx, d1, d2;
map<ll, ll> cnt;
void get_sz(int x, int par) {
sz[x] = 1, mx[x] = 0;
for(auto i : mp[x]) {
int to = es[i] ^ x; cc ++;
if(par == i || vis[to]) continue;
get_sz(to, i);
sz[x] += sz[to];
mx[x] = max(mx[x], sz[to]);
}
}
int get_cen(int x, int par, int tot) {
int best = x;
for(auto i : mp[x]) {
int to = es[i] ^ x; cc++;
if(i == par || vis[to]) continue;
int cur = get_cen(to, i, tot);
if(max(mx[cur], tot - sz[cur]) <
max(mx[best], tot - sz[best])) best = cur;
}
return best;
}
void dfs(int x, int par, int dd1 = 0, int dd2 = 0) {
d1[x] = dd1, d2[x] = dd2;
pre[ii ++] = x;
for(auto i : mp[x]) {
int to = es[i] ^ x; cc++;
if(i == par || vis[to]) continue;
dfs(to, i, dd1 + 1, dd2 + cost[i]);
}
}
void solve(int x, int par) {
get_sz(x, -1);
int cen = get_cen(x, -1, sz[x]);
vis[cen] = 1, cnt.clear();
cnt[0] = 0;
for(auto i : mp[cen]) {
int to = es[i] ^ cen; cc++;
if(vis[to]) continue;
ii = 0, dfs(to, -1, 1, cost[i]);
rep(j, 0, ii - 1) {
int cur = pre[j], v = k - d2[cur];
if(cnt.find(v) != cnt.end())
ans = min(ans, d1[cur] + cnt[v]);
}
rep(j, 0, ii - 1) {
int cur = pre[j], v = d2[cur];
if(cnt.find(v) == cnt.end()) cnt[v] = d1[cur];
else cnt[v] = min(cnt[v], (ll)d1[cur]);
}
}
for(auto i : mp[cen]) {
int to = es[i] ^ cen; cc++;
if(vis[to]) continue;
solve(to, i);
}
return;
}
int best_path(int N, int K, int H[][2], int L[]) {
k = K, n = N, ii = 0;
ans = INF, cc = 0;
mp.assign(n + 1, vector<int>());
pre.assign(n + 1, 0);
vis.assign(n + 1, 0);
sz.assign(n + 1, 0);
mx.assign(n + 1, 0);
assert(cc <= 1e9);
d1.assign(n + 1, 0);
d2.assign(n + 1, 0);
rep(i, 0, n - 2) {
int a = H[i][0] + 1, b = H[i][1] + 1;
mp[a].push_back(es.size());
mp[b].push_back(es.size());
es.push_back(a ^ b);
cost.push_back(L[i]);
}
solve(1, -1);
return (ans == INF ? -1 : ans);
}
Compilation message
race.cpp:5: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
5 | #pragma loop-opt(on)
|
race.cpp:25:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
25 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
race.cpp:25:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
25 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
3 ms |
460 KB |
Output is correct |
23 |
Correct |
3 ms |
460 KB |
Output is correct |
24 |
Correct |
2 ms |
460 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
460 KB |
Output is correct |
30 |
Correct |
3 ms |
460 KB |
Output is correct |
31 |
Correct |
3 ms |
460 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
33 |
Correct |
3 ms |
460 KB |
Output is correct |
34 |
Correct |
2 ms |
460 KB |
Output is correct |
35 |
Correct |
3 ms |
460 KB |
Output is correct |
36 |
Correct |
2 ms |
460 KB |
Output is correct |
37 |
Correct |
2 ms |
416 KB |
Output is correct |
38 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
413 ms |
10240 KB |
Output is correct |
20 |
Correct |
463 ms |
10084 KB |
Output is correct |
21 |
Correct |
443 ms |
10296 KB |
Output is correct |
22 |
Correct |
379 ms |
10164 KB |
Output is correct |
23 |
Correct |
434 ms |
10152 KB |
Output is correct |
24 |
Correct |
229 ms |
10420 KB |
Output is correct |
25 |
Correct |
340 ms |
14348 KB |
Output is correct |
26 |
Correct |
181 ms |
16436 KB |
Output is correct |
27 |
Correct |
522 ms |
20612 KB |
Output is correct |
28 |
Correct |
1406 ms |
44760 KB |
Output is correct |
29 |
Correct |
1478 ms |
46684 KB |
Output is correct |
30 |
Correct |
446 ms |
23536 KB |
Output is correct |
31 |
Correct |
460 ms |
23536 KB |
Output is correct |
32 |
Correct |
636 ms |
23504 KB |
Output is correct |
33 |
Correct |
909 ms |
22940 KB |
Output is correct |
34 |
Correct |
1281 ms |
35140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
3 ms |
460 KB |
Output is correct |
23 |
Correct |
3 ms |
460 KB |
Output is correct |
24 |
Correct |
2 ms |
460 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
460 KB |
Output is correct |
30 |
Correct |
3 ms |
460 KB |
Output is correct |
31 |
Correct |
3 ms |
460 KB |
Output is correct |
32 |
Correct |
2 ms |
460 KB |
Output is correct |
33 |
Correct |
3 ms |
460 KB |
Output is correct |
34 |
Correct |
2 ms |
460 KB |
Output is correct |
35 |
Correct |
3 ms |
460 KB |
Output is correct |
36 |
Correct |
2 ms |
460 KB |
Output is correct |
37 |
Correct |
2 ms |
416 KB |
Output is correct |
38 |
Correct |
2 ms |
460 KB |
Output is correct |
39 |
Correct |
413 ms |
10240 KB |
Output is correct |
40 |
Correct |
463 ms |
10084 KB |
Output is correct |
41 |
Correct |
443 ms |
10296 KB |
Output is correct |
42 |
Correct |
379 ms |
10164 KB |
Output is correct |
43 |
Correct |
434 ms |
10152 KB |
Output is correct |
44 |
Correct |
229 ms |
10420 KB |
Output is correct |
45 |
Correct |
340 ms |
14348 KB |
Output is correct |
46 |
Correct |
181 ms |
16436 KB |
Output is correct |
47 |
Correct |
522 ms |
20612 KB |
Output is correct |
48 |
Correct |
1406 ms |
44760 KB |
Output is correct |
49 |
Correct |
1478 ms |
46684 KB |
Output is correct |
50 |
Correct |
446 ms |
23536 KB |
Output is correct |
51 |
Correct |
460 ms |
23536 KB |
Output is correct |
52 |
Correct |
636 ms |
23504 KB |
Output is correct |
53 |
Correct |
909 ms |
22940 KB |
Output is correct |
54 |
Correct |
1281 ms |
35140 KB |
Output is correct |
55 |
Correct |
29 ms |
1740 KB |
Output is correct |
56 |
Correct |
19 ms |
1340 KB |
Output is correct |
57 |
Correct |
207 ms |
11344 KB |
Output is correct |
58 |
Correct |
60 ms |
11560 KB |
Output is correct |
59 |
Correct |
387 ms |
22400 KB |
Output is correct |
60 |
Correct |
1469 ms |
46180 KB |
Output is correct |
61 |
Correct |
526 ms |
25212 KB |
Output is correct |
62 |
Correct |
454 ms |
23552 KB |
Output is correct |
63 |
Correct |
631 ms |
23496 KB |
Output is correct |
64 |
Correct |
1717 ms |
28896 KB |
Output is correct |
65 |
Correct |
1526 ms |
35280 KB |
Output is correct |
66 |
Correct |
1380 ms |
44612 KB |
Output is correct |
67 |
Correct |
216 ms |
23588 KB |
Output is correct |
68 |
Correct |
861 ms |
33736 KB |
Output is correct |
69 |
Correct |
842 ms |
34048 KB |
Output is correct |
70 |
Correct |
826 ms |
32396 KB |
Output is correct |