# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1093108 |
2024-09-26T00:49:39 Z |
anhthi |
Race (IOI11_race) |
C++14 |
|
652 ms |
47016 KB |
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define pb push_back
#define max_rng *max_element
#define min_rng *min_element
#define rep(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define forn(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
template <class X, class Y>
inline bool maximize(X &x, Y y) {
return (x < y ? x = y, true : false);
}
template <class X, class Y>
inline bool minimize(X &x, Y y) {
return (x > y ? x = y, true : false);
}
template <class X>
inline void compress(vector<X> &a) {
sort(all(a));
a.resize(unique(all(a)) - a.begin());
}
int ctz(ll x) { return __builtin_ctzll(x); }
int lg(ll x) { return 63 - __builtin_clzll(x); }
int popcount(ll x) { return __builtin_popcount(x); }
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) {
return l + abs((ll) rng()) % (r - l + 1);
}
const ll oo = (ll) 1e17;
const int inf = (ll) 2e9 + 7, mod = (ll) 1e9 + 7;
const int mxn = 3e5 + 5, mxm = 3e2 + 5;
const int LG = 18, BASE = 311, BLOCK = 350;
void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
void sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
int n, k;
ll w[mxn];
vector<pair<int, int>> g[mxn];
bool del[mxn];
int childs[mxn];
int getSz(int u, int p) {
childs[u] = 1;
for (auto &[v, i] : g[u]) if (v != p && !del[v]) {
childs[u] += getSz(v, u);
}
return childs[u];
}
int getCen(int u, int p, int sz) {
for (auto &[v, i] : g[u]) if (v != p && !del[v]) {
if (2 * childs[v] > sz) return getCen(v, u, sz);
}
return u;
}
int ans = inf;
map<ll, int> mp;
void dfs(int u, int p, bool flag, ll dist, int d = 1) {
if (dist > k) return;
if (flag) {
if (mp.find(k - dist) != mp.end()) {
minimize(ans, mp[k - dist] + d);
}
}
else {
if (mp.find(dist) == mp.end())
mp[dist] = d;
else minimize(mp[dist], d);
}
for (auto &[v, i] : g[u]) if (v != p && !del[v])
dfs(v, u, flag, dist + w[i], d + 1);
return;
}
void solve(int root) {
mp.clear();
mp[0] = 0;
for (auto &[v, i] : g[root]) if (v != root && !del[v]) {
dfs(v, root, 1, w[i]);
dfs(v, root, 0, w[i]);
}
return;
}
void dnc(int u) {
int sz = getSz(u, 0);
int cen = getCen(u, 0, sz);
solve(cen);
del[cen] = true;
for (auto &[v, i] : g[cen]) if (!del[v])
dnc(v);
}
int best_path(int N, int K, int H[][2], int L[]) {
n = N; k = K;
forn(i, 0, n - 2) {
int u = H[i][0];
int v = H[i][1];
u++; v++;
g[u].pb(mp(v, i));
g[v].pb(mp(u, i));
}
forn(i, 0, n - 2) w[i] = L[i];
dnc(1);
return (ans == inf ? -1 : ans);
}
//int main(void) {
//
// ios_base::sync_with_stdio(0);
// cin.tie(0); cout.tie(0);
//
// #define TASK "cquery"
// if (fopen(TASK".inp", "r")) {
// freopen(TASK".inp", "r", stdin);
// freopen(TASK".out", "w", stdout);
// }
//
// int a[][2] = {{0, 1}, {1, 2}, {1, 3}};
// int b[] = {1, 2, 4};
// best_path(4, 3, a, b);
//
// return 0;
//}
Compilation message
race.cpp: In function 'int getSz(int, int)':
race.cpp:63:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
63 | for (auto &[v, i] : g[u]) if (v != p && !del[v]) {
| ^
race.cpp: In function 'int getCen(int, int, int)':
race.cpp:70:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
70 | for (auto &[v, i] : g[u]) if (v != p && !del[v]) {
| ^
race.cpp: In function 'void dfs(int, int, bool, long long int, int)':
race.cpp:92:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
92 | for (auto &[v, i] : g[u]) if (v != p && !del[v])
| ^
race.cpp: In function 'void solve(int)':
race.cpp:102:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
102 | for (auto &[v, i] : g[root]) if (v != root && !del[v]) {
| ^
race.cpp: In function 'void dnc(int)':
race.cpp:117:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
117 | for (auto &[v, i] : g[cen]) if (!del[v])
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
12752 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
12636 KB |
Output is correct |
11 |
Correct |
2 ms |
12636 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
1 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
12636 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
1 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
12752 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
12636 KB |
Output is correct |
11 |
Correct |
2 ms |
12636 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
1 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
12636 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
1 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10584 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
1 ms |
10588 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
2 ms |
10584 KB |
Output is correct |
23 |
Correct |
2 ms |
10588 KB |
Output is correct |
24 |
Correct |
2 ms |
12636 KB |
Output is correct |
25 |
Correct |
2 ms |
12636 KB |
Output is correct |
26 |
Correct |
2 ms |
10588 KB |
Output is correct |
27 |
Correct |
2 ms |
10584 KB |
Output is correct |
28 |
Correct |
2 ms |
10588 KB |
Output is correct |
29 |
Correct |
3 ms |
10588 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
31 |
Correct |
2 ms |
10588 KB |
Output is correct |
32 |
Correct |
3 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10680 KB |
Output is correct |
35 |
Correct |
2 ms |
12636 KB |
Output is correct |
36 |
Correct |
2 ms |
10720 KB |
Output is correct |
37 |
Correct |
2 ms |
10588 KB |
Output is correct |
38 |
Correct |
3 ms |
10588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
12752 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
12636 KB |
Output is correct |
11 |
Correct |
2 ms |
12636 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
1 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
12636 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
1 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10584 KB |
Output is correct |
19 |
Correct |
131 ms |
17516 KB |
Output is correct |
20 |
Correct |
115 ms |
17500 KB |
Output is correct |
21 |
Correct |
135 ms |
17752 KB |
Output is correct |
22 |
Correct |
121 ms |
19036 KB |
Output is correct |
23 |
Correct |
51 ms |
17744 KB |
Output is correct |
24 |
Correct |
49 ms |
17752 KB |
Output is correct |
25 |
Correct |
85 ms |
20212 KB |
Output is correct |
26 |
Correct |
69 ms |
23124 KB |
Output is correct |
27 |
Correct |
118 ms |
24912 KB |
Output is correct |
28 |
Correct |
151 ms |
37260 KB |
Output is correct |
29 |
Correct |
156 ms |
35156 KB |
Output is correct |
30 |
Correct |
122 ms |
24764 KB |
Output is correct |
31 |
Correct |
121 ms |
24924 KB |
Output is correct |
32 |
Correct |
127 ms |
24792 KB |
Output is correct |
33 |
Correct |
169 ms |
23636 KB |
Output is correct |
34 |
Correct |
98 ms |
24660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10588 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
2 ms |
10588 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
10588 KB |
Output is correct |
8 |
Correct |
2 ms |
12752 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
12636 KB |
Output is correct |
11 |
Correct |
2 ms |
12636 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
1 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
12636 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
1 ms |
10588 KB |
Output is correct |
17 |
Correct |
2 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10584 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
1 ms |
10588 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
2 ms |
10584 KB |
Output is correct |
23 |
Correct |
2 ms |
10588 KB |
Output is correct |
24 |
Correct |
2 ms |
12636 KB |
Output is correct |
25 |
Correct |
2 ms |
12636 KB |
Output is correct |
26 |
Correct |
2 ms |
10588 KB |
Output is correct |
27 |
Correct |
2 ms |
10584 KB |
Output is correct |
28 |
Correct |
2 ms |
10588 KB |
Output is correct |
29 |
Correct |
3 ms |
10588 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
31 |
Correct |
2 ms |
10588 KB |
Output is correct |
32 |
Correct |
3 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10680 KB |
Output is correct |
35 |
Correct |
2 ms |
12636 KB |
Output is correct |
36 |
Correct |
2 ms |
10720 KB |
Output is correct |
37 |
Correct |
2 ms |
10588 KB |
Output is correct |
38 |
Correct |
3 ms |
10588 KB |
Output is correct |
39 |
Correct |
131 ms |
17516 KB |
Output is correct |
40 |
Correct |
115 ms |
17500 KB |
Output is correct |
41 |
Correct |
135 ms |
17752 KB |
Output is correct |
42 |
Correct |
121 ms |
19036 KB |
Output is correct |
43 |
Correct |
51 ms |
17744 KB |
Output is correct |
44 |
Correct |
49 ms |
17752 KB |
Output is correct |
45 |
Correct |
85 ms |
20212 KB |
Output is correct |
46 |
Correct |
69 ms |
23124 KB |
Output is correct |
47 |
Correct |
118 ms |
24912 KB |
Output is correct |
48 |
Correct |
151 ms |
37260 KB |
Output is correct |
49 |
Correct |
156 ms |
35156 KB |
Output is correct |
50 |
Correct |
122 ms |
24764 KB |
Output is correct |
51 |
Correct |
121 ms |
24924 KB |
Output is correct |
52 |
Correct |
127 ms |
24792 KB |
Output is correct |
53 |
Correct |
169 ms |
23636 KB |
Output is correct |
54 |
Correct |
98 ms |
24660 KB |
Output is correct |
55 |
Correct |
13 ms |
11356 KB |
Output is correct |
56 |
Correct |
10 ms |
11228 KB |
Output is correct |
57 |
Correct |
85 ms |
19076 KB |
Output is correct |
58 |
Correct |
32 ms |
17348 KB |
Output is correct |
59 |
Correct |
201 ms |
27784 KB |
Output is correct |
60 |
Correct |
566 ms |
47016 KB |
Output is correct |
61 |
Correct |
180 ms |
25172 KB |
Output is correct |
62 |
Correct |
185 ms |
25048 KB |
Output is correct |
63 |
Correct |
199 ms |
25168 KB |
Output is correct |
64 |
Correct |
652 ms |
32324 KB |
Output is correct |
65 |
Correct |
95 ms |
25680 KB |
Output is correct |
66 |
Correct |
346 ms |
33772 KB |
Output is correct |
67 |
Correct |
68 ms |
25540 KB |
Output is correct |
68 |
Correct |
257 ms |
31700 KB |
Output is correct |
69 |
Correct |
273 ms |
31688 KB |
Output is correct |
70 |
Correct |
236 ms |
29628 KB |
Output is correct |