# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
136595 |
2019-07-25T17:18:08 Z |
dolphingarlic |
Race (IOI11_race) |
C++14 |
|
1031 ms |
52748 KB |
#include <bits/stdc++.h>
//#include "race.h"
using namespace std;
const int N = 2e5 + 7;
const int inf = 1e9;
const int K = 1e6 + 7;
const int T = 1e8;
int n, k;
vector <int> adj[N], len[N], adj_c[N], rv;
int sz[N];
bool used[N];
int find_cnt(int u, int p = -1){
sz[u] = 1;
for(int to: adj[u]){
if(p == to || used[to]){
continue;
}
sz[u] += find_cnt(to, u);
}
return sz[u];
}
int find_centroid(int u, int cnt, int p = -1){
for(int to: adj[u]){
if(to == p || used[to]){
continue;
}
if(sz[to] > (cnt / 2)){
return find_centroid(to, cnt, u);
}
}
return u;
}
int root;
void decompose(int u, int p = -1){
int cnt = find_cnt(u);
int cen = find_centroid(u, cnt);
//cout << p << " -> " << cen << endl;
if(p != -1){
adj_c[p].push_back(cen);
}
else{
root = cen;
}
used[cen] = true;
for(int to: adj[cen]){
if(!used[to]){
decompose(to, cen);
}
}
used[cen] = false;
}
int arr[K];
vector<pair<int, int> > vec;
int ans = inf;
void solve_k(int u, int pr, int sum, int d){
if(sum > k || used[u]){
return;
}
vec.push_back({sum, d});
if(arr[k - sum] != inf){
ans = min(ans, d + arr[k - sum]);
}
for(int i = 0; i < adj[u].size(); i++){
int to = adj[u][i];
int l = len[u][i];
if(used[to] || to == pr){
continue;
}
solve_k(to, u, sum + l, d + 1);
}
}
int sum_vec = 0;
clock_t t;
inline float time_passed(){
return (float)(clock() - t) / (float)CLOCKS_PER_SEC;
}
void solve(int u){
used[u] = true;
for(int to: adj_c[u]){
solve(to);
}
rv.clear();
/*if(time_passed() > (float)2.7){
return;
}*/
for(int i = 0; i < adj[u].size(); i++){
vec.clear();
solve_k(adj[u][i], u, len[u][i], 1);
sum_vec += vec.size();
for(pair<int, int> p: vec){
if(arr[p.first] == inf){
rv.push_back(p.first);
}
arr[p.first] = min(arr[p.first], p.second);
}
}
for(int i: rv){
arr[i] = inf;
}
used[u] = false;
}
int best_path(int _n, int _k, int _h[][2], int _l[]){
t = clock();
n = _n;
k = _k;
for(int i = 0; i < n - 1; i++){
adj[_h[i][0]].push_back(_h[i][1]);
adj[_h[i][1]].push_back(_h[i][0]);
len[_h[i][0]].push_back(_l[i]);
len[_h[i][1]].push_back(_l[i]);
}
decompose(0);
for(int i = 1; i < K; i++){
arr[i] = inf;
}
solve(root);
/*if(sum_vec > T){
return -21;
}*/
if(ans == inf){
return -1;
}
return ans;
}
Compilation message
race.cpp: In function 'void solve_k(int, int, int, int)':
race.cpp:84:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < adj[u].size(); i++){
~~^~~~~~~~~~~~~~~
race.cpp: In function 'void solve(int)':
race.cpp:115:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < adj[u].size(); i++){
~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
18424 KB |
Output is correct |
2 |
Correct |
18 ms |
18296 KB |
Output is correct |
3 |
Correct |
19 ms |
18296 KB |
Output is correct |
4 |
Correct |
18 ms |
18296 KB |
Output is correct |
5 |
Correct |
18 ms |
18424 KB |
Output is correct |
6 |
Correct |
18 ms |
18424 KB |
Output is correct |
7 |
Correct |
18 ms |
18296 KB |
Output is correct |
8 |
Correct |
19 ms |
18424 KB |
Output is correct |
9 |
Correct |
19 ms |
18424 KB |
Output is correct |
10 |
Correct |
18 ms |
18296 KB |
Output is correct |
11 |
Correct |
18 ms |
18296 KB |
Output is correct |
12 |
Correct |
18 ms |
18396 KB |
Output is correct |
13 |
Correct |
18 ms |
18468 KB |
Output is correct |
14 |
Correct |
18 ms |
18424 KB |
Output is correct |
15 |
Correct |
19 ms |
18296 KB |
Output is correct |
16 |
Correct |
18 ms |
18296 KB |
Output is correct |
17 |
Correct |
18 ms |
18296 KB |
Output is correct |
18 |
Correct |
22 ms |
18408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
18424 KB |
Output is correct |
2 |
Correct |
18 ms |
18296 KB |
Output is correct |
3 |
Correct |
19 ms |
18296 KB |
Output is correct |
4 |
Correct |
18 ms |
18296 KB |
Output is correct |
5 |
Correct |
18 ms |
18424 KB |
Output is correct |
6 |
Correct |
18 ms |
18424 KB |
Output is correct |
7 |
Correct |
18 ms |
18296 KB |
Output is correct |
8 |
Correct |
19 ms |
18424 KB |
Output is correct |
9 |
Correct |
19 ms |
18424 KB |
Output is correct |
10 |
Correct |
18 ms |
18296 KB |
Output is correct |
11 |
Correct |
18 ms |
18296 KB |
Output is correct |
12 |
Correct |
18 ms |
18396 KB |
Output is correct |
13 |
Correct |
18 ms |
18468 KB |
Output is correct |
14 |
Correct |
18 ms |
18424 KB |
Output is correct |
15 |
Correct |
19 ms |
18296 KB |
Output is correct |
16 |
Correct |
18 ms |
18296 KB |
Output is correct |
17 |
Correct |
18 ms |
18296 KB |
Output is correct |
18 |
Correct |
22 ms |
18408 KB |
Output is correct |
19 |
Correct |
18 ms |
18424 KB |
Output is correct |
20 |
Correct |
22 ms |
18424 KB |
Output is correct |
21 |
Correct |
20 ms |
18428 KB |
Output is correct |
22 |
Correct |
19 ms |
18424 KB |
Output is correct |
23 |
Correct |
20 ms |
18424 KB |
Output is correct |
24 |
Correct |
19 ms |
18424 KB |
Output is correct |
25 |
Correct |
20 ms |
18424 KB |
Output is correct |
26 |
Correct |
20 ms |
18396 KB |
Output is correct |
27 |
Correct |
19 ms |
18424 KB |
Output is correct |
28 |
Correct |
19 ms |
18424 KB |
Output is correct |
29 |
Correct |
23 ms |
18428 KB |
Output is correct |
30 |
Correct |
19 ms |
18424 KB |
Output is correct |
31 |
Correct |
19 ms |
18428 KB |
Output is correct |
32 |
Correct |
19 ms |
18424 KB |
Output is correct |
33 |
Correct |
19 ms |
18424 KB |
Output is correct |
34 |
Correct |
19 ms |
18424 KB |
Output is correct |
35 |
Correct |
19 ms |
18424 KB |
Output is correct |
36 |
Correct |
19 ms |
18424 KB |
Output is correct |
37 |
Correct |
19 ms |
18424 KB |
Output is correct |
38 |
Correct |
20 ms |
18424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
18424 KB |
Output is correct |
2 |
Correct |
18 ms |
18296 KB |
Output is correct |
3 |
Correct |
19 ms |
18296 KB |
Output is correct |
4 |
Correct |
18 ms |
18296 KB |
Output is correct |
5 |
Correct |
18 ms |
18424 KB |
Output is correct |
6 |
Correct |
18 ms |
18424 KB |
Output is correct |
7 |
Correct |
18 ms |
18296 KB |
Output is correct |
8 |
Correct |
19 ms |
18424 KB |
Output is correct |
9 |
Correct |
19 ms |
18424 KB |
Output is correct |
10 |
Correct |
18 ms |
18296 KB |
Output is correct |
11 |
Correct |
18 ms |
18296 KB |
Output is correct |
12 |
Correct |
18 ms |
18396 KB |
Output is correct |
13 |
Correct |
18 ms |
18468 KB |
Output is correct |
14 |
Correct |
18 ms |
18424 KB |
Output is correct |
15 |
Correct |
19 ms |
18296 KB |
Output is correct |
16 |
Correct |
18 ms |
18296 KB |
Output is correct |
17 |
Correct |
18 ms |
18296 KB |
Output is correct |
18 |
Correct |
22 ms |
18408 KB |
Output is correct |
19 |
Correct |
229 ms |
29252 KB |
Output is correct |
20 |
Correct |
229 ms |
29432 KB |
Output is correct |
21 |
Correct |
239 ms |
29708 KB |
Output is correct |
22 |
Correct |
236 ms |
29636 KB |
Output is correct |
23 |
Correct |
195 ms |
29340 KB |
Output is correct |
24 |
Correct |
132 ms |
28748 KB |
Output is correct |
25 |
Correct |
258 ms |
32252 KB |
Output is correct |
26 |
Correct |
152 ms |
34936 KB |
Output is correct |
27 |
Correct |
371 ms |
40888 KB |
Output is correct |
28 |
Correct |
596 ms |
50680 KB |
Output is correct |
29 |
Correct |
605 ms |
50132 KB |
Output is correct |
30 |
Correct |
378 ms |
40884 KB |
Output is correct |
31 |
Correct |
363 ms |
40888 KB |
Output is correct |
32 |
Correct |
444 ms |
40940 KB |
Output is correct |
33 |
Correct |
589 ms |
40824 KB |
Output is correct |
34 |
Correct |
474 ms |
41688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
18424 KB |
Output is correct |
2 |
Correct |
18 ms |
18296 KB |
Output is correct |
3 |
Correct |
19 ms |
18296 KB |
Output is correct |
4 |
Correct |
18 ms |
18296 KB |
Output is correct |
5 |
Correct |
18 ms |
18424 KB |
Output is correct |
6 |
Correct |
18 ms |
18424 KB |
Output is correct |
7 |
Correct |
18 ms |
18296 KB |
Output is correct |
8 |
Correct |
19 ms |
18424 KB |
Output is correct |
9 |
Correct |
19 ms |
18424 KB |
Output is correct |
10 |
Correct |
18 ms |
18296 KB |
Output is correct |
11 |
Correct |
18 ms |
18296 KB |
Output is correct |
12 |
Correct |
18 ms |
18396 KB |
Output is correct |
13 |
Correct |
18 ms |
18468 KB |
Output is correct |
14 |
Correct |
18 ms |
18424 KB |
Output is correct |
15 |
Correct |
19 ms |
18296 KB |
Output is correct |
16 |
Correct |
18 ms |
18296 KB |
Output is correct |
17 |
Correct |
18 ms |
18296 KB |
Output is correct |
18 |
Correct |
22 ms |
18408 KB |
Output is correct |
19 |
Correct |
18 ms |
18424 KB |
Output is correct |
20 |
Correct |
22 ms |
18424 KB |
Output is correct |
21 |
Correct |
20 ms |
18428 KB |
Output is correct |
22 |
Correct |
19 ms |
18424 KB |
Output is correct |
23 |
Correct |
20 ms |
18424 KB |
Output is correct |
24 |
Correct |
19 ms |
18424 KB |
Output is correct |
25 |
Correct |
20 ms |
18424 KB |
Output is correct |
26 |
Correct |
20 ms |
18396 KB |
Output is correct |
27 |
Correct |
19 ms |
18424 KB |
Output is correct |
28 |
Correct |
19 ms |
18424 KB |
Output is correct |
29 |
Correct |
23 ms |
18428 KB |
Output is correct |
30 |
Correct |
19 ms |
18424 KB |
Output is correct |
31 |
Correct |
19 ms |
18428 KB |
Output is correct |
32 |
Correct |
19 ms |
18424 KB |
Output is correct |
33 |
Correct |
19 ms |
18424 KB |
Output is correct |
34 |
Correct |
19 ms |
18424 KB |
Output is correct |
35 |
Correct |
19 ms |
18424 KB |
Output is correct |
36 |
Correct |
19 ms |
18424 KB |
Output is correct |
37 |
Correct |
19 ms |
18424 KB |
Output is correct |
38 |
Correct |
20 ms |
18424 KB |
Output is correct |
39 |
Correct |
229 ms |
29252 KB |
Output is correct |
40 |
Correct |
229 ms |
29432 KB |
Output is correct |
41 |
Correct |
239 ms |
29708 KB |
Output is correct |
42 |
Correct |
236 ms |
29636 KB |
Output is correct |
43 |
Correct |
195 ms |
29340 KB |
Output is correct |
44 |
Correct |
132 ms |
28748 KB |
Output is correct |
45 |
Correct |
258 ms |
32252 KB |
Output is correct |
46 |
Correct |
152 ms |
34936 KB |
Output is correct |
47 |
Correct |
371 ms |
40888 KB |
Output is correct |
48 |
Correct |
596 ms |
50680 KB |
Output is correct |
49 |
Correct |
605 ms |
50132 KB |
Output is correct |
50 |
Correct |
378 ms |
40884 KB |
Output is correct |
51 |
Correct |
363 ms |
40888 KB |
Output is correct |
52 |
Correct |
444 ms |
40940 KB |
Output is correct |
53 |
Correct |
589 ms |
40824 KB |
Output is correct |
54 |
Correct |
474 ms |
41688 KB |
Output is correct |
55 |
Correct |
35 ms |
19536 KB |
Output is correct |
56 |
Correct |
31 ms |
19576 KB |
Output is correct |
57 |
Correct |
136 ms |
29848 KB |
Output is correct |
58 |
Correct |
78 ms |
28648 KB |
Output is correct |
59 |
Correct |
170 ms |
35548 KB |
Output is correct |
60 |
Correct |
1031 ms |
52748 KB |
Output is correct |
61 |
Correct |
385 ms |
41080 KB |
Output is correct |
62 |
Correct |
431 ms |
41040 KB |
Output is correct |
63 |
Correct |
499 ms |
40952 KB |
Output is correct |
64 |
Correct |
693 ms |
42480 KB |
Output is correct |
65 |
Correct |
506 ms |
41428 KB |
Output is correct |
66 |
Correct |
729 ms |
48884 KB |
Output is correct |
67 |
Correct |
239 ms |
40100 KB |
Output is correct |
68 |
Correct |
472 ms |
41768 KB |
Output is correct |
69 |
Correct |
473 ms |
42028 KB |
Output is correct |
70 |
Correct |
429 ms |
40872 KB |
Output is correct |