# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1105632 |
2024-10-27T06:48:46 Z |
Nxmkxing |
Race (IOI11_race) |
C++14 |
|
3000 ms |
26440 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const ll inf = 1e18;
const int MxN = 2e5 + 10;
const int MxL = 19;
int n, k, dep[MxN], up[MxN][MxL];
ll dis[MxN];
vector<pii> adj[MxN];
void dfs(int u, int p) {
for (auto [v, w] : adj[u]) {
if (v == p) continue;
dep[v] = dep[u] + 1;
dis[v] = dis[u] + w;
up[v][0] = u;
for (int i = 1; i < MxL; i++) up[v][i] = up[up[v][i-1]][i-1];
dfs(v, u);
}
}
int lca(int u, int v) {
if (dep[u] < dep[v]) swap(u, v);
int k = dep[u] - dep[v];
for (int i = 0; i < MxL; i++) if (k & (1 << i)) u = up[u][i];
if (u == v) return u;
for (int i = MxL - 1; i >= 0; i--) if (up[u][i] != up[v][i]) u = up[u][i], v = up[v][i];
return up[u][0];
}
int best_path(int N, int K, int H[][2], int L[])
{
n = N, k = K;
for (int i = 0; i < n - 1; i++) {
int u = H[i][0];
int v = H[i][1];
int w = L[i];
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
dfs(0, -1);
ll ans = inf;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int l = lca(i, j);
ll d = dep[i] + dep[j] - dep[l] * 2;
ll dist = dis[i] + dis[j] - dis[l] * 2;
if (dist == k) ans = min(ans, d);
}
}
if (ans == inf) return -1;
return ans;
}
Compilation message
race.cpp: In function 'void dfs(int, int)':
race.cpp:16:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
16 | for (auto [v, w] : adj[u]) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10576 KB |
Output is correct |
2 |
Correct |
2 ms |
10576 KB |
Output is correct |
3 |
Correct |
2 ms |
10576 KB |
Output is correct |
4 |
Correct |
2 ms |
10576 KB |
Output is correct |
5 |
Correct |
2 ms |
10576 KB |
Output is correct |
6 |
Correct |
2 ms |
10576 KB |
Output is correct |
7 |
Correct |
2 ms |
10576 KB |
Output is correct |
8 |
Correct |
2 ms |
10576 KB |
Output is correct |
9 |
Correct |
3 ms |
10576 KB |
Output is correct |
10 |
Correct |
2 ms |
10704 KB |
Output is correct |
11 |
Correct |
2 ms |
10576 KB |
Output is correct |
12 |
Correct |
3 ms |
10576 KB |
Output is correct |
13 |
Correct |
2 ms |
10700 KB |
Output is correct |
14 |
Correct |
2 ms |
10576 KB |
Output is correct |
15 |
Correct |
2 ms |
10576 KB |
Output is correct |
16 |
Correct |
3 ms |
10576 KB |
Output is correct |
17 |
Correct |
2 ms |
10576 KB |
Output is correct |
18 |
Correct |
3 ms |
10700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10576 KB |
Output is correct |
2 |
Correct |
2 ms |
10576 KB |
Output is correct |
3 |
Correct |
2 ms |
10576 KB |
Output is correct |
4 |
Correct |
2 ms |
10576 KB |
Output is correct |
5 |
Correct |
2 ms |
10576 KB |
Output is correct |
6 |
Correct |
2 ms |
10576 KB |
Output is correct |
7 |
Correct |
2 ms |
10576 KB |
Output is correct |
8 |
Correct |
2 ms |
10576 KB |
Output is correct |
9 |
Correct |
3 ms |
10576 KB |
Output is correct |
10 |
Correct |
2 ms |
10704 KB |
Output is correct |
11 |
Correct |
2 ms |
10576 KB |
Output is correct |
12 |
Correct |
3 ms |
10576 KB |
Output is correct |
13 |
Correct |
2 ms |
10700 KB |
Output is correct |
14 |
Correct |
2 ms |
10576 KB |
Output is correct |
15 |
Correct |
2 ms |
10576 KB |
Output is correct |
16 |
Correct |
3 ms |
10576 KB |
Output is correct |
17 |
Correct |
2 ms |
10576 KB |
Output is correct |
18 |
Correct |
3 ms |
10700 KB |
Output is correct |
19 |
Correct |
3 ms |
10576 KB |
Output is correct |
20 |
Correct |
3 ms |
10576 KB |
Output is correct |
21 |
Correct |
28 ms |
10764 KB |
Output is correct |
22 |
Correct |
33 ms |
10832 KB |
Output is correct |
23 |
Correct |
32 ms |
10576 KB |
Output is correct |
24 |
Correct |
28 ms |
10576 KB |
Output is correct |
25 |
Correct |
28 ms |
10576 KB |
Output is correct |
26 |
Correct |
28 ms |
10576 KB |
Output is correct |
27 |
Correct |
29 ms |
10576 KB |
Output is correct |
28 |
Correct |
34 ms |
10576 KB |
Output is correct |
29 |
Correct |
28 ms |
10576 KB |
Output is correct |
30 |
Correct |
28 ms |
10576 KB |
Output is correct |
31 |
Correct |
28 ms |
10576 KB |
Output is correct |
32 |
Correct |
29 ms |
10576 KB |
Output is correct |
33 |
Correct |
31 ms |
10576 KB |
Output is correct |
34 |
Correct |
32 ms |
10576 KB |
Output is correct |
35 |
Correct |
31 ms |
10576 KB |
Output is correct |
36 |
Correct |
25 ms |
10716 KB |
Output is correct |
37 |
Correct |
28 ms |
10576 KB |
Output is correct |
38 |
Correct |
34 ms |
10576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10576 KB |
Output is correct |
2 |
Correct |
2 ms |
10576 KB |
Output is correct |
3 |
Correct |
2 ms |
10576 KB |
Output is correct |
4 |
Correct |
2 ms |
10576 KB |
Output is correct |
5 |
Correct |
2 ms |
10576 KB |
Output is correct |
6 |
Correct |
2 ms |
10576 KB |
Output is correct |
7 |
Correct |
2 ms |
10576 KB |
Output is correct |
8 |
Correct |
2 ms |
10576 KB |
Output is correct |
9 |
Correct |
3 ms |
10576 KB |
Output is correct |
10 |
Correct |
2 ms |
10704 KB |
Output is correct |
11 |
Correct |
2 ms |
10576 KB |
Output is correct |
12 |
Correct |
3 ms |
10576 KB |
Output is correct |
13 |
Correct |
2 ms |
10700 KB |
Output is correct |
14 |
Correct |
2 ms |
10576 KB |
Output is correct |
15 |
Correct |
2 ms |
10576 KB |
Output is correct |
16 |
Correct |
3 ms |
10576 KB |
Output is correct |
17 |
Correct |
2 ms |
10576 KB |
Output is correct |
18 |
Correct |
3 ms |
10700 KB |
Output is correct |
19 |
Execution timed out |
3058 ms |
26440 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10576 KB |
Output is correct |
2 |
Correct |
2 ms |
10576 KB |
Output is correct |
3 |
Correct |
2 ms |
10576 KB |
Output is correct |
4 |
Correct |
2 ms |
10576 KB |
Output is correct |
5 |
Correct |
2 ms |
10576 KB |
Output is correct |
6 |
Correct |
2 ms |
10576 KB |
Output is correct |
7 |
Correct |
2 ms |
10576 KB |
Output is correct |
8 |
Correct |
2 ms |
10576 KB |
Output is correct |
9 |
Correct |
3 ms |
10576 KB |
Output is correct |
10 |
Correct |
2 ms |
10704 KB |
Output is correct |
11 |
Correct |
2 ms |
10576 KB |
Output is correct |
12 |
Correct |
3 ms |
10576 KB |
Output is correct |
13 |
Correct |
2 ms |
10700 KB |
Output is correct |
14 |
Correct |
2 ms |
10576 KB |
Output is correct |
15 |
Correct |
2 ms |
10576 KB |
Output is correct |
16 |
Correct |
3 ms |
10576 KB |
Output is correct |
17 |
Correct |
2 ms |
10576 KB |
Output is correct |
18 |
Correct |
3 ms |
10700 KB |
Output is correct |
19 |
Correct |
3 ms |
10576 KB |
Output is correct |
20 |
Correct |
3 ms |
10576 KB |
Output is correct |
21 |
Correct |
28 ms |
10764 KB |
Output is correct |
22 |
Correct |
33 ms |
10832 KB |
Output is correct |
23 |
Correct |
32 ms |
10576 KB |
Output is correct |
24 |
Correct |
28 ms |
10576 KB |
Output is correct |
25 |
Correct |
28 ms |
10576 KB |
Output is correct |
26 |
Correct |
28 ms |
10576 KB |
Output is correct |
27 |
Correct |
29 ms |
10576 KB |
Output is correct |
28 |
Correct |
34 ms |
10576 KB |
Output is correct |
29 |
Correct |
28 ms |
10576 KB |
Output is correct |
30 |
Correct |
28 ms |
10576 KB |
Output is correct |
31 |
Correct |
28 ms |
10576 KB |
Output is correct |
32 |
Correct |
29 ms |
10576 KB |
Output is correct |
33 |
Correct |
31 ms |
10576 KB |
Output is correct |
34 |
Correct |
32 ms |
10576 KB |
Output is correct |
35 |
Correct |
31 ms |
10576 KB |
Output is correct |
36 |
Correct |
25 ms |
10716 KB |
Output is correct |
37 |
Correct |
28 ms |
10576 KB |
Output is correct |
38 |
Correct |
34 ms |
10576 KB |
Output is correct |
39 |
Execution timed out |
3058 ms |
26440 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |