# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
433469 |
2021-06-19T20:57:20 Z |
timg8710 |
Race (IOI11_race) |
C++17 |
|
578 ms |
107460 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
#define pb push_back
#define f first
#define s second
const int maxn = 2e5+20;
vector<pii> adj[maxn];
map<ll, ll> info[maxn];
ll dist[maxn], height[maxn]; //define dist relative to root
int N, K, u, v; ll ret;
void dfs1(int u, int p, ll c, int h){
info[u][c] = h;
dist[u] = c; height[u] = h;
for(auto n : adj[u]){
if(p == n.f) continue;
dfs1(n.f, u, c + n.s, h + 1);
}
}
void dfs(int u, int p){
ll target = K + 2*dist[u];
for(auto n : adj[u]){
if(n.f == p) continue;
dfs(n.f, u);
if(info[n.f].size() > info[u].size()){
swap(info[n.f], info[u]);
}
for(auto i : info[n.f]){
if(info[u].find(target - i.f) != info[u].end()){
ret = min(ret, info[u][target - i.f] + i.s - 2*height[u]);
}
}
for(auto i : info[n.f]){
if(info[u].find(i.f) == info[u].end()){
info[u].insert(i);
}else{
info[u][i.f] = min(info[u][i.f], i.s);
}
}
}
}
//new to c++, feel free to give suggestions on how to improve code/make it easier to read
int best_path(int n, int k, int edges[][2], int weights[]){
if(k == 1) return 0;
N = n; K = k; ret = INT_MAX;
for(int i = 0; i<n-1; i++){
u = edges[i][0]; v = edges[i][1];
adj[u].pb(pii(v, weights[i])); adj[v].pb(pii(u, weights[i]));
}
dfs1(0, -1, 0, 0);
dfs(0, -1);
return ret == INT_MAX ? -1 : ret;
}
// int main(){
// cin >> N >> K;
// int edges[N][2]; int weights[N];
// for(int i = 0; i<N-1; i++){
// cin >> u >> v;
// edges[i][0] = u; edges[i][1] = v;
// }
// for(int i = 0; i<N-1; i++){
// cin >> u; weights[i] = u;
// }
// cout << best_path(N, K, edges, weights);
// }
/*
11 12
0 1
0 2
2 3
3 4
4 5
0 6
6 7
6 8
8 9
8 10
3
4
5
4
6
3
2
5
6
7
4 3
0 1
1 2
1 3
1
2
4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14412 KB |
Output is correct |
2 |
Correct |
10 ms |
14384 KB |
Output is correct |
3 |
Correct |
10 ms |
14412 KB |
Output is correct |
4 |
Correct |
10 ms |
14412 KB |
Output is correct |
5 |
Correct |
10 ms |
14448 KB |
Output is correct |
6 |
Correct |
10 ms |
14452 KB |
Output is correct |
7 |
Correct |
10 ms |
14452 KB |
Output is correct |
8 |
Correct |
9 ms |
14336 KB |
Output is correct |
9 |
Correct |
9 ms |
14412 KB |
Output is correct |
10 |
Correct |
10 ms |
14412 KB |
Output is correct |
11 |
Correct |
10 ms |
14412 KB |
Output is correct |
12 |
Correct |
9 ms |
14380 KB |
Output is correct |
13 |
Correct |
9 ms |
14416 KB |
Output is correct |
14 |
Correct |
10 ms |
14428 KB |
Output is correct |
15 |
Correct |
9 ms |
14412 KB |
Output is correct |
16 |
Correct |
10 ms |
14412 KB |
Output is correct |
17 |
Correct |
10 ms |
14412 KB |
Output is correct |
18 |
Correct |
9 ms |
14412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14412 KB |
Output is correct |
2 |
Correct |
10 ms |
14384 KB |
Output is correct |
3 |
Correct |
10 ms |
14412 KB |
Output is correct |
4 |
Correct |
10 ms |
14412 KB |
Output is correct |
5 |
Correct |
10 ms |
14448 KB |
Output is correct |
6 |
Correct |
10 ms |
14452 KB |
Output is correct |
7 |
Correct |
10 ms |
14452 KB |
Output is correct |
8 |
Correct |
9 ms |
14336 KB |
Output is correct |
9 |
Correct |
9 ms |
14412 KB |
Output is correct |
10 |
Correct |
10 ms |
14412 KB |
Output is correct |
11 |
Correct |
10 ms |
14412 KB |
Output is correct |
12 |
Correct |
9 ms |
14380 KB |
Output is correct |
13 |
Correct |
9 ms |
14416 KB |
Output is correct |
14 |
Correct |
10 ms |
14428 KB |
Output is correct |
15 |
Correct |
9 ms |
14412 KB |
Output is correct |
16 |
Correct |
10 ms |
14412 KB |
Output is correct |
17 |
Correct |
10 ms |
14412 KB |
Output is correct |
18 |
Correct |
9 ms |
14412 KB |
Output is correct |
19 |
Correct |
9 ms |
14388 KB |
Output is correct |
20 |
Correct |
9 ms |
14412 KB |
Output is correct |
21 |
Correct |
10 ms |
14668 KB |
Output is correct |
22 |
Correct |
10 ms |
14752 KB |
Output is correct |
23 |
Correct |
11 ms |
14668 KB |
Output is correct |
24 |
Correct |
10 ms |
14668 KB |
Output is correct |
25 |
Correct |
11 ms |
14724 KB |
Output is correct |
26 |
Correct |
11 ms |
14668 KB |
Output is correct |
27 |
Correct |
10 ms |
14552 KB |
Output is correct |
28 |
Correct |
11 ms |
14732 KB |
Output is correct |
29 |
Correct |
10 ms |
14668 KB |
Output is correct |
30 |
Correct |
11 ms |
14644 KB |
Output is correct |
31 |
Correct |
10 ms |
14668 KB |
Output is correct |
32 |
Correct |
10 ms |
14716 KB |
Output is correct |
33 |
Correct |
10 ms |
14664 KB |
Output is correct |
34 |
Correct |
10 ms |
14668 KB |
Output is correct |
35 |
Correct |
10 ms |
14668 KB |
Output is correct |
36 |
Correct |
10 ms |
14612 KB |
Output is correct |
37 |
Correct |
10 ms |
14616 KB |
Output is correct |
38 |
Correct |
11 ms |
14668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14412 KB |
Output is correct |
2 |
Correct |
10 ms |
14384 KB |
Output is correct |
3 |
Correct |
10 ms |
14412 KB |
Output is correct |
4 |
Correct |
10 ms |
14412 KB |
Output is correct |
5 |
Correct |
10 ms |
14448 KB |
Output is correct |
6 |
Correct |
10 ms |
14452 KB |
Output is correct |
7 |
Correct |
10 ms |
14452 KB |
Output is correct |
8 |
Correct |
9 ms |
14336 KB |
Output is correct |
9 |
Correct |
9 ms |
14412 KB |
Output is correct |
10 |
Correct |
10 ms |
14412 KB |
Output is correct |
11 |
Correct |
10 ms |
14412 KB |
Output is correct |
12 |
Correct |
9 ms |
14380 KB |
Output is correct |
13 |
Correct |
9 ms |
14416 KB |
Output is correct |
14 |
Correct |
10 ms |
14428 KB |
Output is correct |
15 |
Correct |
9 ms |
14412 KB |
Output is correct |
16 |
Correct |
10 ms |
14412 KB |
Output is correct |
17 |
Correct |
10 ms |
14412 KB |
Output is correct |
18 |
Correct |
9 ms |
14412 KB |
Output is correct |
19 |
Correct |
166 ms |
37744 KB |
Output is correct |
20 |
Correct |
170 ms |
37832 KB |
Output is correct |
21 |
Correct |
166 ms |
37672 KB |
Output is correct |
22 |
Correct |
169 ms |
37020 KB |
Output is correct |
23 |
Correct |
221 ms |
49872 KB |
Output is correct |
24 |
Correct |
163 ms |
40020 KB |
Output is correct |
25 |
Correct |
141 ms |
38596 KB |
Output is correct |
26 |
Correct |
77 ms |
46924 KB |
Output is correct |
27 |
Correct |
256 ms |
49608 KB |
Output is correct |
28 |
Correct |
374 ms |
91852 KB |
Output is correct |
29 |
Correct |
375 ms |
90016 KB |
Output is correct |
30 |
Correct |
258 ms |
49604 KB |
Output is correct |
31 |
Correct |
254 ms |
49692 KB |
Output is correct |
32 |
Correct |
369 ms |
49752 KB |
Output is correct |
33 |
Correct |
340 ms |
54724 KB |
Output is correct |
34 |
Correct |
441 ms |
86584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14412 KB |
Output is correct |
2 |
Correct |
10 ms |
14384 KB |
Output is correct |
3 |
Correct |
10 ms |
14412 KB |
Output is correct |
4 |
Correct |
10 ms |
14412 KB |
Output is correct |
5 |
Correct |
10 ms |
14448 KB |
Output is correct |
6 |
Correct |
10 ms |
14452 KB |
Output is correct |
7 |
Correct |
10 ms |
14452 KB |
Output is correct |
8 |
Correct |
9 ms |
14336 KB |
Output is correct |
9 |
Correct |
9 ms |
14412 KB |
Output is correct |
10 |
Correct |
10 ms |
14412 KB |
Output is correct |
11 |
Correct |
10 ms |
14412 KB |
Output is correct |
12 |
Correct |
9 ms |
14380 KB |
Output is correct |
13 |
Correct |
9 ms |
14416 KB |
Output is correct |
14 |
Correct |
10 ms |
14428 KB |
Output is correct |
15 |
Correct |
9 ms |
14412 KB |
Output is correct |
16 |
Correct |
10 ms |
14412 KB |
Output is correct |
17 |
Correct |
10 ms |
14412 KB |
Output is correct |
18 |
Correct |
9 ms |
14412 KB |
Output is correct |
19 |
Correct |
9 ms |
14388 KB |
Output is correct |
20 |
Correct |
9 ms |
14412 KB |
Output is correct |
21 |
Correct |
10 ms |
14668 KB |
Output is correct |
22 |
Correct |
10 ms |
14752 KB |
Output is correct |
23 |
Correct |
11 ms |
14668 KB |
Output is correct |
24 |
Correct |
10 ms |
14668 KB |
Output is correct |
25 |
Correct |
11 ms |
14724 KB |
Output is correct |
26 |
Correct |
11 ms |
14668 KB |
Output is correct |
27 |
Correct |
10 ms |
14552 KB |
Output is correct |
28 |
Correct |
11 ms |
14732 KB |
Output is correct |
29 |
Correct |
10 ms |
14668 KB |
Output is correct |
30 |
Correct |
11 ms |
14644 KB |
Output is correct |
31 |
Correct |
10 ms |
14668 KB |
Output is correct |
32 |
Correct |
10 ms |
14716 KB |
Output is correct |
33 |
Correct |
10 ms |
14664 KB |
Output is correct |
34 |
Correct |
10 ms |
14668 KB |
Output is correct |
35 |
Correct |
10 ms |
14668 KB |
Output is correct |
36 |
Correct |
10 ms |
14612 KB |
Output is correct |
37 |
Correct |
10 ms |
14616 KB |
Output is correct |
38 |
Correct |
11 ms |
14668 KB |
Output is correct |
39 |
Correct |
166 ms |
37744 KB |
Output is correct |
40 |
Correct |
170 ms |
37832 KB |
Output is correct |
41 |
Correct |
166 ms |
37672 KB |
Output is correct |
42 |
Correct |
169 ms |
37020 KB |
Output is correct |
43 |
Correct |
221 ms |
49872 KB |
Output is correct |
44 |
Correct |
163 ms |
40020 KB |
Output is correct |
45 |
Correct |
141 ms |
38596 KB |
Output is correct |
46 |
Correct |
77 ms |
46924 KB |
Output is correct |
47 |
Correct |
256 ms |
49608 KB |
Output is correct |
48 |
Correct |
374 ms |
91852 KB |
Output is correct |
49 |
Correct |
375 ms |
90016 KB |
Output is correct |
50 |
Correct |
258 ms |
49604 KB |
Output is correct |
51 |
Correct |
254 ms |
49692 KB |
Output is correct |
52 |
Correct |
369 ms |
49752 KB |
Output is correct |
53 |
Correct |
340 ms |
54724 KB |
Output is correct |
54 |
Correct |
441 ms |
86584 KB |
Output is correct |
55 |
Correct |
24 ms |
17720 KB |
Output is correct |
56 |
Correct |
18 ms |
16460 KB |
Output is correct |
57 |
Correct |
89 ms |
35260 KB |
Output is correct |
58 |
Correct |
62 ms |
29260 KB |
Output is correct |
59 |
Correct |
113 ms |
54468 KB |
Output is correct |
60 |
Correct |
358 ms |
93404 KB |
Output is correct |
61 |
Correct |
295 ms |
56096 KB |
Output is correct |
62 |
Correct |
246 ms |
52548 KB |
Output is correct |
63 |
Correct |
367 ms |
52888 KB |
Output is correct |
64 |
Correct |
573 ms |
107460 KB |
Output is correct |
65 |
Correct |
578 ms |
105508 KB |
Output is correct |
66 |
Correct |
384 ms |
88976 KB |
Output is correct |
67 |
Correct |
237 ms |
45488 KB |
Output is correct |
68 |
Correct |
480 ms |
69156 KB |
Output is correct |
69 |
Correct |
509 ms |
73808 KB |
Output is correct |
70 |
Correct |
440 ms |
66544 KB |
Output is correct |