# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
681410 |
2023-01-13T03:42:15 Z |
phoebe |
Race (IOI11_race) |
C++17 |
|
2587 ms |
43936 KB |
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
// #define int long long
#define ll long long
#define pii pair<int, int>
#define F first
#define S second
#define PB push_back
#define ALL(x) x.begin(), x.end()
#define FOR(i, n) for (int i = 0; i < n; i++)
#define NYOOM ios::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
const int INF = 1e9 + 7;
const ll LLINF = 1ll<<60;
const int maxn = 2e5 + 10;
int n, k, sz[maxn];
vector<pair<pii, int>> adj[maxn];
map<int, int> small, large;
set<int> deleted;
void init(int v, int p){
sz[v] = 1;
for (auto x : adj[v]){
int u = x.F.F, w = x.F.S, i = x.S;
if (deleted.count(i)) continue;
if (u == p) continue;
init(u, v); sz[v] += sz[u];
}
}
int get_centroid(int v, int p, int pog){
for (auto x : adj[v]){
int u = x.F.F, w = x.F.S, i = x.S;
if (deleted.count(i)) continue;
if (u == p) continue;
if (sz[u] * 2 > pog) return get_centroid(u, v, pog);
}
return v;
}
void dfs(int v, int p, int h, int cnt){
if (small.count(h)) small[h] = min(small[h], cnt);
else small[h] = cnt;
for (auto x : adj[v]){
int u = x.F.F, w = x.F.S, i = x.S;
if (deleted.count(i)) continue;
if (u == p) continue;
dfs(u, v, h + w, cnt + 1);
}
}
int solve(int v){
init(v, v);
v = get_centroid(v, -1, sz[v]);
int re = INF;
large.clear();
small.clear();
large[0] = 0;
for (auto x : adj[v]){
int u = x.F.F, w = x.F.S, i = x.S;
if (deleted.count(i)) continue;
dfs(u, v, w, 1);
for (auto bruh : small){
if (large.count(k - bruh.F)){
re = min(re, bruh.S + large[k - bruh.F]);
}
}
for (auto bruh : small){
if (large.count(bruh.F)) large[bruh.F] = min(large[bruh.F], bruh.S);
else large[bruh.F] = bruh.S;
}
small.clear();
}
for (auto x : adj[v]){
int u = x.F.F, w = x.F.S, i = x.S;
if (deleted.count(i)) continue;
deleted.insert(i);
re = min(re, solve(u));
}
return re;
}
int best_path(int N, int K, int h[][2], int l[]){
n = N, k = K;
FOR(i, n - 1){
adj[h[i][0]].PB({{h[i][1], l[i]}, i});
adj[h[i][1]].PB({{h[i][0], l[i]}, i});
}
int re = solve(0);
return (re == INF ? -1 : re);
}
Compilation message
race.cpp: In function 'void init(int, int)':
race.cpp:27:24: warning: unused variable 'w' [-Wunused-variable]
27 | int u = x.F.F, w = x.F.S, i = x.S;
| ^
race.cpp: In function 'int get_centroid(int, int, int)':
race.cpp:36:24: warning: unused variable 'w' [-Wunused-variable]
36 | int u = x.F.F, w = x.F.S, i = x.S;
| ^
race.cpp: In function 'int solve(int)':
race.cpp:78:24: warning: unused variable 'w' [-Wunused-variable]
78 | int u = x.F.F, w = x.F.S, i = x.S;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5008 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5012 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5008 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
4 ms |
4996 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5008 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5012 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5008 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
4 ms |
4996 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
5012 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
6 ms |
5076 KB |
Output is correct |
22 |
Correct |
8 ms |
5076 KB |
Output is correct |
23 |
Correct |
7 ms |
5076 KB |
Output is correct |
24 |
Correct |
6 ms |
5076 KB |
Output is correct |
25 |
Correct |
6 ms |
5156 KB |
Output is correct |
26 |
Correct |
6 ms |
5076 KB |
Output is correct |
27 |
Correct |
5 ms |
5076 KB |
Output is correct |
28 |
Correct |
6 ms |
5076 KB |
Output is correct |
29 |
Correct |
6 ms |
5076 KB |
Output is correct |
30 |
Correct |
6 ms |
5076 KB |
Output is correct |
31 |
Correct |
7 ms |
5076 KB |
Output is correct |
32 |
Correct |
6 ms |
5076 KB |
Output is correct |
33 |
Correct |
7 ms |
5076 KB |
Output is correct |
34 |
Correct |
8 ms |
5152 KB |
Output is correct |
35 |
Correct |
6 ms |
5076 KB |
Output is correct |
36 |
Correct |
5 ms |
5076 KB |
Output is correct |
37 |
Correct |
5 ms |
5076 KB |
Output is correct |
38 |
Correct |
5 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5008 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5012 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5008 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
4 ms |
4996 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
854 ms |
16668 KB |
Output is correct |
20 |
Correct |
835 ms |
16800 KB |
Output is correct |
21 |
Correct |
798 ms |
16836 KB |
Output is correct |
22 |
Correct |
645 ms |
16764 KB |
Output is correct |
23 |
Correct |
657 ms |
17300 KB |
Output is correct |
24 |
Correct |
293 ms |
16996 KB |
Output is correct |
25 |
Correct |
426 ms |
20328 KB |
Output is correct |
26 |
Correct |
411 ms |
21916 KB |
Output is correct |
27 |
Correct |
1233 ms |
28644 KB |
Output is correct |
28 |
Correct |
1794 ms |
43936 KB |
Output is correct |
29 |
Correct |
1938 ms |
43040 KB |
Output is correct |
30 |
Correct |
1131 ms |
28580 KB |
Output is correct |
31 |
Correct |
1240 ms |
28648 KB |
Output is correct |
32 |
Correct |
1222 ms |
28632 KB |
Output is correct |
33 |
Correct |
1065 ms |
26796 KB |
Output is correct |
34 |
Correct |
1552 ms |
30080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5008 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
5012 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
5008 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
4 ms |
4996 KB |
Output is correct |
15 |
Correct |
4 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
5012 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
6 ms |
5076 KB |
Output is correct |
22 |
Correct |
8 ms |
5076 KB |
Output is correct |
23 |
Correct |
7 ms |
5076 KB |
Output is correct |
24 |
Correct |
6 ms |
5076 KB |
Output is correct |
25 |
Correct |
6 ms |
5156 KB |
Output is correct |
26 |
Correct |
6 ms |
5076 KB |
Output is correct |
27 |
Correct |
5 ms |
5076 KB |
Output is correct |
28 |
Correct |
6 ms |
5076 KB |
Output is correct |
29 |
Correct |
6 ms |
5076 KB |
Output is correct |
30 |
Correct |
6 ms |
5076 KB |
Output is correct |
31 |
Correct |
7 ms |
5076 KB |
Output is correct |
32 |
Correct |
6 ms |
5076 KB |
Output is correct |
33 |
Correct |
7 ms |
5076 KB |
Output is correct |
34 |
Correct |
8 ms |
5152 KB |
Output is correct |
35 |
Correct |
6 ms |
5076 KB |
Output is correct |
36 |
Correct |
5 ms |
5076 KB |
Output is correct |
37 |
Correct |
5 ms |
5076 KB |
Output is correct |
38 |
Correct |
5 ms |
5076 KB |
Output is correct |
39 |
Correct |
854 ms |
16668 KB |
Output is correct |
40 |
Correct |
835 ms |
16800 KB |
Output is correct |
41 |
Correct |
798 ms |
16836 KB |
Output is correct |
42 |
Correct |
645 ms |
16764 KB |
Output is correct |
43 |
Correct |
657 ms |
17300 KB |
Output is correct |
44 |
Correct |
293 ms |
16996 KB |
Output is correct |
45 |
Correct |
426 ms |
20328 KB |
Output is correct |
46 |
Correct |
411 ms |
21916 KB |
Output is correct |
47 |
Correct |
1233 ms |
28644 KB |
Output is correct |
48 |
Correct |
1794 ms |
43936 KB |
Output is correct |
49 |
Correct |
1938 ms |
43040 KB |
Output is correct |
50 |
Correct |
1131 ms |
28580 KB |
Output is correct |
51 |
Correct |
1240 ms |
28648 KB |
Output is correct |
52 |
Correct |
1222 ms |
28632 KB |
Output is correct |
53 |
Correct |
1065 ms |
26796 KB |
Output is correct |
54 |
Correct |
1552 ms |
30080 KB |
Output is correct |
55 |
Correct |
49 ms |
6100 KB |
Output is correct |
56 |
Correct |
45 ms |
6128 KB |
Output is correct |
57 |
Correct |
378 ms |
17224 KB |
Output is correct |
58 |
Correct |
115 ms |
16544 KB |
Output is correct |
59 |
Correct |
736 ms |
23168 KB |
Output is correct |
60 |
Correct |
1785 ms |
42572 KB |
Output is correct |
61 |
Correct |
1238 ms |
28644 KB |
Output is correct |
62 |
Correct |
1216 ms |
28552 KB |
Output is correct |
63 |
Correct |
1216 ms |
28704 KB |
Output is correct |
64 |
Correct |
2587 ms |
29368 KB |
Output is correct |
65 |
Correct |
2215 ms |
30212 KB |
Output is correct |
66 |
Correct |
1744 ms |
41176 KB |
Output is correct |
67 |
Correct |
268 ms |
29388 KB |
Output is correct |
68 |
Correct |
1294 ms |
29428 KB |
Output is correct |
69 |
Correct |
1293 ms |
29788 KB |
Output is correct |
70 |
Correct |
1172 ms |
28388 KB |
Output is correct |