# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
353981 |
2021-01-21T11:20:07 Z |
xt0r3 |
Race (IOI11_race) |
C++14 |
|
1089 ms |
42204 KB |
#include<bits/stdc++.h>
#include "race.h"
using namespace std;
constexpr int MAXN = 2*1e5 + 5, MAXK = 1e6 + 5, INF = 1e8;
bool visited[MAXN];
int c[MAXN], k, mini[MAXK];
vector<int> edges[MAXN], w[MAXN];
int cnt(int id){
visited[id] = 1;
c[id] = 1;
for(int v : edges[id]) if(!visited[v]) c[id] += cnt(v);
visited[id] = 0;
return c[id];
}
int init(int id, int n, int p = -1){
for(int v : edges[id]) if(c[v] > n/2 && !visited[v] && p != v) return init(v, n, id);
return id;
}
int centroid(int id){
return init(id, cnt(id));
}
int calc(int id, int len, int lvl = 1, int p = -1){
int ret = INF;
if(len <= k) ret = min(ret, mini[k-len] + lvl);
for(int i = 0; i < edges[id].size(); i++){
int v = edges[id][i];
if(!visited[v] && v != p) ret = min(ret, calc(v, min(INF, len + w[id][i]), lvl + 1, id));
}
return ret;
}
void add(int id, int len, int lvl = 1, int p = -1){
if(len < MAXK) mini[len] = min(mini[len], lvl);
for(int i = 0; i < edges[id].size(); i++){
int v = edges[id][i];
if(!visited[v] && p != v) add(v, min(INF, len + w[id][i]), lvl + 1, id);
}
}
void res(int id, int len = 0, int p = -1){
if(len < MAXK) mini[len] = INF;
for(int i = 0; i < edges[id].size(); i++){
int v = edges[id][i];
if(!visited[v] && p != v) res(v, min(INF, len + w[id][i]), id);
}
}
int db(int id){
int ret = INF;
mini[0] = 0;
for(int i = 0; i < edges[id].size(); i++){
int v = edges[id][i];
//cout << v << ' ' << visited[v] << endl;
if(visited[v]) continue;
ret = min(ret, calc(v, w[id][i], 1, id));
//cout << "ITT" << endl;
add(v, w[id][i], 1, id);
//cout << "ITT" << endl;
}
res(id);
return ret;
}
int process(int id){
//cout << "eppen: " << id << endl;
int ret = db(id);
visited[id] = 1;
for(int v : edges[id]) if(!visited[v]) ret = min(ret, process(centroid(v)));
//cout << id << ' ' << ret << endl;
return ret;
}
int best_path(int N, int K, int H[][2], int L[])
{
fill(mini, mini + MAXK, INF);
k = K;
for(int i = 0; i < N-1; i++){
edges[H[i][0]].push_back(H[i][1]);
w[H[i][0]].push_back(L[i]);
swap(H[i][0], H[i][1]);
edges[H[i][0]].push_back(H[i][1]);
w[H[i][0]].push_back(L[i]);
}
int ret = process(centroid(0));
return (ret == INF ? -1 : ret);
}
Compilation message
race.cpp: In function 'int calc(int, int, int, int)':
race.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i = 0; i < edges[id].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~
race.cpp: In function 'void add(int, int, int, int)':
race.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i = 0; i < edges[id].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~
race.cpp: In function 'void res(int, int, int)':
race.cpp:48:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i = 0; i < edges[id].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~
race.cpp: In function 'int db(int)':
race.cpp:57:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i = 0; i < edges[id].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
13676 KB |
Output is correct |
2 |
Correct |
9 ms |
13676 KB |
Output is correct |
3 |
Correct |
10 ms |
13676 KB |
Output is correct |
4 |
Correct |
10 ms |
13676 KB |
Output is correct |
5 |
Correct |
9 ms |
13676 KB |
Output is correct |
6 |
Correct |
9 ms |
13676 KB |
Output is correct |
7 |
Correct |
9 ms |
13676 KB |
Output is correct |
8 |
Correct |
9 ms |
13676 KB |
Output is correct |
9 |
Correct |
9 ms |
13676 KB |
Output is correct |
10 |
Correct |
9 ms |
13676 KB |
Output is correct |
11 |
Correct |
10 ms |
13676 KB |
Output is correct |
12 |
Correct |
11 ms |
13676 KB |
Output is correct |
13 |
Correct |
9 ms |
13676 KB |
Output is correct |
14 |
Correct |
9 ms |
13676 KB |
Output is correct |
15 |
Correct |
9 ms |
13676 KB |
Output is correct |
16 |
Correct |
11 ms |
13676 KB |
Output is correct |
17 |
Correct |
9 ms |
13676 KB |
Output is correct |
18 |
Correct |
9 ms |
13676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
13676 KB |
Output is correct |
2 |
Correct |
9 ms |
13676 KB |
Output is correct |
3 |
Correct |
10 ms |
13676 KB |
Output is correct |
4 |
Correct |
10 ms |
13676 KB |
Output is correct |
5 |
Correct |
9 ms |
13676 KB |
Output is correct |
6 |
Correct |
9 ms |
13676 KB |
Output is correct |
7 |
Correct |
9 ms |
13676 KB |
Output is correct |
8 |
Correct |
9 ms |
13676 KB |
Output is correct |
9 |
Correct |
9 ms |
13676 KB |
Output is correct |
10 |
Correct |
9 ms |
13676 KB |
Output is correct |
11 |
Correct |
10 ms |
13676 KB |
Output is correct |
12 |
Correct |
11 ms |
13676 KB |
Output is correct |
13 |
Correct |
9 ms |
13676 KB |
Output is correct |
14 |
Correct |
9 ms |
13676 KB |
Output is correct |
15 |
Correct |
9 ms |
13676 KB |
Output is correct |
16 |
Correct |
11 ms |
13676 KB |
Output is correct |
17 |
Correct |
9 ms |
13676 KB |
Output is correct |
18 |
Correct |
9 ms |
13676 KB |
Output is correct |
19 |
Correct |
10 ms |
13676 KB |
Output is correct |
20 |
Correct |
10 ms |
13676 KB |
Output is correct |
21 |
Correct |
10 ms |
13804 KB |
Output is correct |
22 |
Correct |
10 ms |
13804 KB |
Output is correct |
23 |
Correct |
10 ms |
13804 KB |
Output is correct |
24 |
Correct |
13 ms |
13824 KB |
Output is correct |
25 |
Correct |
10 ms |
13804 KB |
Output is correct |
26 |
Correct |
10 ms |
13804 KB |
Output is correct |
27 |
Correct |
10 ms |
13804 KB |
Output is correct |
28 |
Correct |
10 ms |
13804 KB |
Output is correct |
29 |
Correct |
11 ms |
13804 KB |
Output is correct |
30 |
Correct |
10 ms |
13804 KB |
Output is correct |
31 |
Correct |
11 ms |
13804 KB |
Output is correct |
32 |
Correct |
10 ms |
13804 KB |
Output is correct |
33 |
Correct |
10 ms |
13804 KB |
Output is correct |
34 |
Correct |
10 ms |
13804 KB |
Output is correct |
35 |
Correct |
10 ms |
13804 KB |
Output is correct |
36 |
Correct |
10 ms |
13804 KB |
Output is correct |
37 |
Correct |
10 ms |
13804 KB |
Output is correct |
38 |
Correct |
11 ms |
13676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
13676 KB |
Output is correct |
2 |
Correct |
9 ms |
13676 KB |
Output is correct |
3 |
Correct |
10 ms |
13676 KB |
Output is correct |
4 |
Correct |
10 ms |
13676 KB |
Output is correct |
5 |
Correct |
9 ms |
13676 KB |
Output is correct |
6 |
Correct |
9 ms |
13676 KB |
Output is correct |
7 |
Correct |
9 ms |
13676 KB |
Output is correct |
8 |
Correct |
9 ms |
13676 KB |
Output is correct |
9 |
Correct |
9 ms |
13676 KB |
Output is correct |
10 |
Correct |
9 ms |
13676 KB |
Output is correct |
11 |
Correct |
10 ms |
13676 KB |
Output is correct |
12 |
Correct |
11 ms |
13676 KB |
Output is correct |
13 |
Correct |
9 ms |
13676 KB |
Output is correct |
14 |
Correct |
9 ms |
13676 KB |
Output is correct |
15 |
Correct |
9 ms |
13676 KB |
Output is correct |
16 |
Correct |
11 ms |
13676 KB |
Output is correct |
17 |
Correct |
9 ms |
13676 KB |
Output is correct |
18 |
Correct |
9 ms |
13676 KB |
Output is correct |
19 |
Correct |
351 ms |
23020 KB |
Output is correct |
20 |
Correct |
362 ms |
23020 KB |
Output is correct |
21 |
Correct |
343 ms |
23020 KB |
Output is correct |
22 |
Correct |
320 ms |
23256 KB |
Output is correct |
23 |
Correct |
262 ms |
23020 KB |
Output is correct |
24 |
Correct |
153 ms |
23532 KB |
Output is correct |
25 |
Correct |
313 ms |
26988 KB |
Output is correct |
26 |
Correct |
140 ms |
27628 KB |
Output is correct |
27 |
Correct |
387 ms |
33736 KB |
Output is correct |
28 |
Correct |
893 ms |
42204 KB |
Output is correct |
29 |
Correct |
903 ms |
41324 KB |
Output is correct |
30 |
Correct |
375 ms |
33644 KB |
Output is correct |
31 |
Correct |
395 ms |
33644 KB |
Output is correct |
32 |
Correct |
539 ms |
33900 KB |
Output is correct |
33 |
Correct |
622 ms |
32628 KB |
Output is correct |
34 |
Correct |
650 ms |
33516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
13676 KB |
Output is correct |
2 |
Correct |
9 ms |
13676 KB |
Output is correct |
3 |
Correct |
10 ms |
13676 KB |
Output is correct |
4 |
Correct |
10 ms |
13676 KB |
Output is correct |
5 |
Correct |
9 ms |
13676 KB |
Output is correct |
6 |
Correct |
9 ms |
13676 KB |
Output is correct |
7 |
Correct |
9 ms |
13676 KB |
Output is correct |
8 |
Correct |
9 ms |
13676 KB |
Output is correct |
9 |
Correct |
9 ms |
13676 KB |
Output is correct |
10 |
Correct |
9 ms |
13676 KB |
Output is correct |
11 |
Correct |
10 ms |
13676 KB |
Output is correct |
12 |
Correct |
11 ms |
13676 KB |
Output is correct |
13 |
Correct |
9 ms |
13676 KB |
Output is correct |
14 |
Correct |
9 ms |
13676 KB |
Output is correct |
15 |
Correct |
9 ms |
13676 KB |
Output is correct |
16 |
Correct |
11 ms |
13676 KB |
Output is correct |
17 |
Correct |
9 ms |
13676 KB |
Output is correct |
18 |
Correct |
9 ms |
13676 KB |
Output is correct |
19 |
Correct |
10 ms |
13676 KB |
Output is correct |
20 |
Correct |
10 ms |
13676 KB |
Output is correct |
21 |
Correct |
10 ms |
13804 KB |
Output is correct |
22 |
Correct |
10 ms |
13804 KB |
Output is correct |
23 |
Correct |
10 ms |
13804 KB |
Output is correct |
24 |
Correct |
13 ms |
13824 KB |
Output is correct |
25 |
Correct |
10 ms |
13804 KB |
Output is correct |
26 |
Correct |
10 ms |
13804 KB |
Output is correct |
27 |
Correct |
10 ms |
13804 KB |
Output is correct |
28 |
Correct |
10 ms |
13804 KB |
Output is correct |
29 |
Correct |
11 ms |
13804 KB |
Output is correct |
30 |
Correct |
10 ms |
13804 KB |
Output is correct |
31 |
Correct |
11 ms |
13804 KB |
Output is correct |
32 |
Correct |
10 ms |
13804 KB |
Output is correct |
33 |
Correct |
10 ms |
13804 KB |
Output is correct |
34 |
Correct |
10 ms |
13804 KB |
Output is correct |
35 |
Correct |
10 ms |
13804 KB |
Output is correct |
36 |
Correct |
10 ms |
13804 KB |
Output is correct |
37 |
Correct |
10 ms |
13804 KB |
Output is correct |
38 |
Correct |
11 ms |
13676 KB |
Output is correct |
39 |
Correct |
351 ms |
23020 KB |
Output is correct |
40 |
Correct |
362 ms |
23020 KB |
Output is correct |
41 |
Correct |
343 ms |
23020 KB |
Output is correct |
42 |
Correct |
320 ms |
23256 KB |
Output is correct |
43 |
Correct |
262 ms |
23020 KB |
Output is correct |
44 |
Correct |
153 ms |
23532 KB |
Output is correct |
45 |
Correct |
313 ms |
26988 KB |
Output is correct |
46 |
Correct |
140 ms |
27628 KB |
Output is correct |
47 |
Correct |
387 ms |
33736 KB |
Output is correct |
48 |
Correct |
893 ms |
42204 KB |
Output is correct |
49 |
Correct |
903 ms |
41324 KB |
Output is correct |
50 |
Correct |
375 ms |
33644 KB |
Output is correct |
51 |
Correct |
395 ms |
33644 KB |
Output is correct |
52 |
Correct |
539 ms |
33900 KB |
Output is correct |
53 |
Correct |
622 ms |
32628 KB |
Output is correct |
54 |
Correct |
650 ms |
33516 KB |
Output is correct |
55 |
Correct |
21 ms |
14572 KB |
Output is correct |
56 |
Correct |
22 ms |
14572 KB |
Output is correct |
57 |
Correct |
123 ms |
22892 KB |
Output is correct |
58 |
Correct |
56 ms |
23672 KB |
Output is correct |
59 |
Correct |
140 ms |
27628 KB |
Output is correct |
60 |
Correct |
927 ms |
41396 KB |
Output is correct |
61 |
Correct |
383 ms |
33772 KB |
Output is correct |
62 |
Correct |
383 ms |
33772 KB |
Output is correct |
63 |
Correct |
529 ms |
33660 KB |
Output is correct |
64 |
Correct |
1089 ms |
33260 KB |
Output is correct |
65 |
Correct |
835 ms |
33888 KB |
Output is correct |
66 |
Correct |
967 ms |
40684 KB |
Output is correct |
67 |
Correct |
252 ms |
34388 KB |
Output is correct |
68 |
Correct |
552 ms |
34436 KB |
Output is correct |
69 |
Correct |
551 ms |
34668 KB |
Output is correct |
70 |
Correct |
535 ms |
33644 KB |
Output is correct |