# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
923863 |
2024-02-08T03:10:18 Z |
Whisper |
Race (IOI11_race) |
C++17 |
|
276 ms |
39688 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using T = tuple<ll, ll, ll>;
//#define int long long
#define Base 41
#define sz(a) (int)a.size()
#define FOR(i, a, b) for ( int i = a ; i <= b ; i++ )
#define FORD(i, a, b) for (int i = b; i >= a; i --)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)
#define all(x) x.begin() , x.end()
#define pii pair<int , int>
#define fi first
#define se second
#define Lg(x) 31 - __builtin_clz(x)
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int MAX = 2e5 + 5;
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class X, class Y>
bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {x = y; return 1;}
return 0;
}
template <class X, class Y>
bool maximize(X &x, const Y &y){
X eps = 1e-9;
if (x + eps < y) {x = y; return 1;}
return 0;
}
int numNode, k;
vector<pii> adj[MAX];
int sz[MAX], del[MAX];
void reSubsize(int u, int p){
sz[u] = 1;
for (auto&[v, w] : adj[u]) if(v ^ p){
if (del[v]) continue;
reSubsize(v, u);
sz[u] += sz[v];
}
}
int getCentroid(int u, int p, int siz){
for (auto&[v, w] : adj[u]) if(v ^ p){
if (!del[v] && sz[v] * 2 > siz) return getCentroid(v, u, siz);
}
return u;
}
ll f[5 * MAX];
ll ans = LINF;
vector<int> save;
void dfs(int u, int p, int l, int dep, bool ok){
if (l > k) return;
if (ok) minimize(ans, f[k - l] + dep);
else{
minimize(f[l], dep);
save.push_back(l);
}
for (auto&[v, w] : adj[u]) if(v ^ p){
if (!del[v]) dfs(v, u, l + w, dep + 1, ok);
}
}
void decompose(int root){
reSubsize(root, -1);
int siz = sz[root];
root = getCentroid(root, -1, siz);
del[root] = 1;
f[0] = 0;
for (auto&[v, w] : adj[root]){
if (del[v]) continue;
dfs(v, root, w, 1, 1);
dfs(v, root, w, 1, 0);
}
for (auto&v : save) f[v] = 1e18;
save.clear();
for (auto&[v, w] : adj[root]) if (!del[v]){
decompose(v);
}
}
int best_path(int N, int K, int H[][2], int L[]) {
numNode = N, k = K;
for (int i = 0; i < numNode - 1; ++i){
int u = H[i][0], v = H[i][1], w = L[i];
++u, ++v;
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
memset(f, 0x3f, sizeof f);
decompose(1);
return (ans > 1e15 ? -1 : ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
18012 KB |
Output is correct |
2 |
Correct |
3 ms |
18012 KB |
Output is correct |
3 |
Correct |
4 ms |
18012 KB |
Output is correct |
4 |
Correct |
3 ms |
18012 KB |
Output is correct |
5 |
Correct |
3 ms |
18012 KB |
Output is correct |
6 |
Correct |
3 ms |
18012 KB |
Output is correct |
7 |
Correct |
3 ms |
18012 KB |
Output is correct |
8 |
Correct |
3 ms |
18012 KB |
Output is correct |
9 |
Correct |
4 ms |
18012 KB |
Output is correct |
10 |
Correct |
3 ms |
18008 KB |
Output is correct |
11 |
Correct |
4 ms |
18012 KB |
Output is correct |
12 |
Correct |
4 ms |
18112 KB |
Output is correct |
13 |
Correct |
4 ms |
18012 KB |
Output is correct |
14 |
Correct |
4 ms |
18012 KB |
Output is correct |
15 |
Correct |
3 ms |
18012 KB |
Output is correct |
16 |
Correct |
3 ms |
18012 KB |
Output is correct |
17 |
Correct |
4 ms |
18008 KB |
Output is correct |
18 |
Correct |
3 ms |
18012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
18012 KB |
Output is correct |
2 |
Correct |
3 ms |
18012 KB |
Output is correct |
3 |
Correct |
4 ms |
18012 KB |
Output is correct |
4 |
Correct |
3 ms |
18012 KB |
Output is correct |
5 |
Correct |
3 ms |
18012 KB |
Output is correct |
6 |
Correct |
3 ms |
18012 KB |
Output is correct |
7 |
Correct |
3 ms |
18012 KB |
Output is correct |
8 |
Correct |
3 ms |
18012 KB |
Output is correct |
9 |
Correct |
4 ms |
18012 KB |
Output is correct |
10 |
Correct |
3 ms |
18008 KB |
Output is correct |
11 |
Correct |
4 ms |
18012 KB |
Output is correct |
12 |
Correct |
4 ms |
18112 KB |
Output is correct |
13 |
Correct |
4 ms |
18012 KB |
Output is correct |
14 |
Correct |
4 ms |
18012 KB |
Output is correct |
15 |
Correct |
3 ms |
18012 KB |
Output is correct |
16 |
Correct |
3 ms |
18012 KB |
Output is correct |
17 |
Correct |
4 ms |
18008 KB |
Output is correct |
18 |
Correct |
3 ms |
18012 KB |
Output is correct |
19 |
Correct |
3 ms |
18012 KB |
Output is correct |
20 |
Correct |
3 ms |
18012 KB |
Output is correct |
21 |
Correct |
4 ms |
18012 KB |
Output is correct |
22 |
Correct |
4 ms |
18012 KB |
Output is correct |
23 |
Correct |
4 ms |
18012 KB |
Output is correct |
24 |
Correct |
4 ms |
18012 KB |
Output is correct |
25 |
Correct |
4 ms |
18012 KB |
Output is correct |
26 |
Correct |
4 ms |
18008 KB |
Output is correct |
27 |
Correct |
4 ms |
18012 KB |
Output is correct |
28 |
Correct |
4 ms |
18012 KB |
Output is correct |
29 |
Correct |
4 ms |
18104 KB |
Output is correct |
30 |
Correct |
4 ms |
18012 KB |
Output is correct |
31 |
Correct |
4 ms |
18008 KB |
Output is correct |
32 |
Correct |
4 ms |
18012 KB |
Output is correct |
33 |
Correct |
4 ms |
18012 KB |
Output is correct |
34 |
Correct |
5 ms |
18012 KB |
Output is correct |
35 |
Correct |
4 ms |
18012 KB |
Output is correct |
36 |
Correct |
3 ms |
18012 KB |
Output is correct |
37 |
Correct |
3 ms |
18012 KB |
Output is correct |
38 |
Correct |
4 ms |
18012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
18012 KB |
Output is correct |
2 |
Correct |
3 ms |
18012 KB |
Output is correct |
3 |
Correct |
4 ms |
18012 KB |
Output is correct |
4 |
Correct |
3 ms |
18012 KB |
Output is correct |
5 |
Correct |
3 ms |
18012 KB |
Output is correct |
6 |
Correct |
3 ms |
18012 KB |
Output is correct |
7 |
Correct |
3 ms |
18012 KB |
Output is correct |
8 |
Correct |
3 ms |
18012 KB |
Output is correct |
9 |
Correct |
4 ms |
18012 KB |
Output is correct |
10 |
Correct |
3 ms |
18008 KB |
Output is correct |
11 |
Correct |
4 ms |
18012 KB |
Output is correct |
12 |
Correct |
4 ms |
18112 KB |
Output is correct |
13 |
Correct |
4 ms |
18012 KB |
Output is correct |
14 |
Correct |
4 ms |
18012 KB |
Output is correct |
15 |
Correct |
3 ms |
18012 KB |
Output is correct |
16 |
Correct |
3 ms |
18012 KB |
Output is correct |
17 |
Correct |
4 ms |
18008 KB |
Output is correct |
18 |
Correct |
3 ms |
18012 KB |
Output is correct |
19 |
Correct |
78 ms |
24152 KB |
Output is correct |
20 |
Correct |
83 ms |
24052 KB |
Output is correct |
21 |
Correct |
85 ms |
24404 KB |
Output is correct |
22 |
Correct |
75 ms |
24524 KB |
Output is correct |
23 |
Correct |
60 ms |
24464 KB |
Output is correct |
24 |
Correct |
37 ms |
24156 KB |
Output is correct |
25 |
Correct |
83 ms |
26704 KB |
Output is correct |
26 |
Correct |
69 ms |
30168 KB |
Output is correct |
27 |
Correct |
102 ms |
27988 KB |
Output is correct |
28 |
Correct |
159 ms |
39264 KB |
Output is correct |
29 |
Correct |
185 ms |
38204 KB |
Output is correct |
30 |
Correct |
112 ms |
28008 KB |
Output is correct |
31 |
Correct |
102 ms |
28004 KB |
Output is correct |
32 |
Correct |
123 ms |
27892 KB |
Output is correct |
33 |
Correct |
121 ms |
26812 KB |
Output is correct |
34 |
Correct |
115 ms |
26708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
18012 KB |
Output is correct |
2 |
Correct |
3 ms |
18012 KB |
Output is correct |
3 |
Correct |
4 ms |
18012 KB |
Output is correct |
4 |
Correct |
3 ms |
18012 KB |
Output is correct |
5 |
Correct |
3 ms |
18012 KB |
Output is correct |
6 |
Correct |
3 ms |
18012 KB |
Output is correct |
7 |
Correct |
3 ms |
18012 KB |
Output is correct |
8 |
Correct |
3 ms |
18012 KB |
Output is correct |
9 |
Correct |
4 ms |
18012 KB |
Output is correct |
10 |
Correct |
3 ms |
18008 KB |
Output is correct |
11 |
Correct |
4 ms |
18012 KB |
Output is correct |
12 |
Correct |
4 ms |
18112 KB |
Output is correct |
13 |
Correct |
4 ms |
18012 KB |
Output is correct |
14 |
Correct |
4 ms |
18012 KB |
Output is correct |
15 |
Correct |
3 ms |
18012 KB |
Output is correct |
16 |
Correct |
3 ms |
18012 KB |
Output is correct |
17 |
Correct |
4 ms |
18008 KB |
Output is correct |
18 |
Correct |
3 ms |
18012 KB |
Output is correct |
19 |
Correct |
3 ms |
18012 KB |
Output is correct |
20 |
Correct |
3 ms |
18012 KB |
Output is correct |
21 |
Correct |
4 ms |
18012 KB |
Output is correct |
22 |
Correct |
4 ms |
18012 KB |
Output is correct |
23 |
Correct |
4 ms |
18012 KB |
Output is correct |
24 |
Correct |
4 ms |
18012 KB |
Output is correct |
25 |
Correct |
4 ms |
18012 KB |
Output is correct |
26 |
Correct |
4 ms |
18008 KB |
Output is correct |
27 |
Correct |
4 ms |
18012 KB |
Output is correct |
28 |
Correct |
4 ms |
18012 KB |
Output is correct |
29 |
Correct |
4 ms |
18104 KB |
Output is correct |
30 |
Correct |
4 ms |
18012 KB |
Output is correct |
31 |
Correct |
4 ms |
18008 KB |
Output is correct |
32 |
Correct |
4 ms |
18012 KB |
Output is correct |
33 |
Correct |
4 ms |
18012 KB |
Output is correct |
34 |
Correct |
5 ms |
18012 KB |
Output is correct |
35 |
Correct |
4 ms |
18012 KB |
Output is correct |
36 |
Correct |
3 ms |
18012 KB |
Output is correct |
37 |
Correct |
3 ms |
18012 KB |
Output is correct |
38 |
Correct |
4 ms |
18012 KB |
Output is correct |
39 |
Correct |
78 ms |
24152 KB |
Output is correct |
40 |
Correct |
83 ms |
24052 KB |
Output is correct |
41 |
Correct |
85 ms |
24404 KB |
Output is correct |
42 |
Correct |
75 ms |
24524 KB |
Output is correct |
43 |
Correct |
60 ms |
24464 KB |
Output is correct |
44 |
Correct |
37 ms |
24156 KB |
Output is correct |
45 |
Correct |
83 ms |
26704 KB |
Output is correct |
46 |
Correct |
69 ms |
30168 KB |
Output is correct |
47 |
Correct |
102 ms |
27988 KB |
Output is correct |
48 |
Correct |
159 ms |
39264 KB |
Output is correct |
49 |
Correct |
185 ms |
38204 KB |
Output is correct |
50 |
Correct |
112 ms |
28008 KB |
Output is correct |
51 |
Correct |
102 ms |
28004 KB |
Output is correct |
52 |
Correct |
123 ms |
27892 KB |
Output is correct |
53 |
Correct |
121 ms |
26812 KB |
Output is correct |
54 |
Correct |
115 ms |
26708 KB |
Output is correct |
55 |
Correct |
8 ms |
18520 KB |
Output is correct |
56 |
Correct |
11 ms |
18524 KB |
Output is correct |
57 |
Correct |
54 ms |
24796 KB |
Output is correct |
58 |
Correct |
27 ms |
25040 KB |
Output is correct |
59 |
Correct |
72 ms |
30404 KB |
Output is correct |
60 |
Correct |
276 ms |
39688 KB |
Output is correct |
61 |
Correct |
122 ms |
28296 KB |
Output is correct |
62 |
Correct |
118 ms |
28880 KB |
Output is correct |
63 |
Correct |
141 ms |
28880 KB |
Output is correct |
64 |
Correct |
254 ms |
28616 KB |
Output is correct |
65 |
Correct |
112 ms |
27732 KB |
Output is correct |
66 |
Correct |
254 ms |
35920 KB |
Output is correct |
67 |
Correct |
71 ms |
29976 KB |
Output is correct |
68 |
Correct |
173 ms |
28780 KB |
Output is correct |
69 |
Correct |
161 ms |
28628 KB |
Output is correct |
70 |
Correct |
161 ms |
28436 KB |
Output is correct |