# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
369967 |
2021-02-22T20:16:20 Z |
Pulgster |
Race (IOI11_race) |
C++17 |
|
2076 ms |
69716 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ed <<endl;
int N;
int K;
int cur = -1;
const int mxn = 200005;
vector<vector<pair<int, int>>> adj(mxn);
vector<int> sz(mxn);
vector<int> forb(mxn);
int findCentroid(int n, int node, int par){
// cerr << imie(node) imie(par) ed;
if(n == 1){
cur = node;
return 0;
}
sz[node] = 1;
bool ok = 1;
for(int i=0;i<(int)adj[node].size();i++){
if(cur != -1){
return 0;
}
int v=adj[node][i].first;
assert(v < forb.size());
if(v != par && !forb[v]){
sz[node] += findCentroid(n, v, node);
if(cur != -1){
return 0;
}
if(sz[v] > n / 2) ok = 0;
}
}
if(n - sz[node] > n / 2){
ok = 0;
}
if(ok){
cur = node;
}
return sz[node];
}
int ans = 2e5+5;
void dfs(int node, int par, int dist, int cost, map<int, int> &global, vector<pair<int, int>> &local){
int k=K;
if(cost == k){
ans = min(ans, dist);
}
if(k-cost > 0 && global[k-cost] != 0){
ans = min(ans, global[k-cost]+dist);
}
for(int i=0;i<(int)adj[node].size();i++){
int v = adj[node][i].first;
if(!forb[v] && v != par && node == cur){
vector<pair<int, int>> their;
dfs(v,node,dist+1,cost+adj[node][i].second, global, their);
for(pair<int, int> j : their){
if(global[j.first] == 0){
global[j.first] = j.second;
}
global[j.first] = min(global[j.first], j.second);
}
continue;
}
if(!forb[v] && v != par){
dfs(v,node,dist+1,cost+adj[node][i].second, global, local);
}
}
local.push_back({cost, dist});
}
void mysol(int node){
int cnt = 0;
if(forb[node]){
return;
}
function<void(int, int)> mdfs = [&](int curnode, int par){
cnt++;
assert(curnode < adj.size());
for(int i=0;i<(int)adj[curnode].size();i++){
int v = adj[curnode][i].first;
assert(v < forb.size());
if(!forb[v] && v != par){
mdfs(v, curnode);
}
}
};
if(cnt == 1){
return;
}
mdfs(node, -1);
map<int, int> global;
cur = -1;
findCentroid(cnt, node, -1);
forb[cur] = 1;
vector<pair<int, int>> local;
dfs(cur, -1, 0, 0, global, local);
// cerr << imie(cur) imie(cnt) ed;
int me = cur;
assert(me != -1);
for(int i=0;i<(int)adj[me].size();i++){
int v = adj[me][i].first;
if(!forb[v]){
mysol(v);
}
}
}
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];
adj[u].push_back({v, l[i]});
adj[v].push_back({u, l[i]});
}
mysol(0);
return (ans > n ? -1 : ans);
}
Compilation message
In file included from /usr/include/c++/9/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
from race.cpp:2:
race.cpp: In function 'int findCentroid(int, int, int)':
race.cpp:27:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | assert(v < forb.size());
| ~~^~~~~~~~~~~~~
race.cpp: In lambda function:
race.cpp:80:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | assert(curnode < adj.size());
| ~~~~~~~~^~~~~~~~~~~~
race.cpp:83:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | assert(v < forb.size());
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6636 KB |
Output is correct |
2 |
Correct |
4 ms |
6636 KB |
Output is correct |
3 |
Correct |
5 ms |
6636 KB |
Output is correct |
4 |
Correct |
4 ms |
6636 KB |
Output is correct |
5 |
Correct |
4 ms |
6636 KB |
Output is correct |
6 |
Correct |
5 ms |
6636 KB |
Output is correct |
7 |
Correct |
4 ms |
6636 KB |
Output is correct |
8 |
Correct |
4 ms |
6636 KB |
Output is correct |
9 |
Correct |
4 ms |
6636 KB |
Output is correct |
10 |
Correct |
5 ms |
6636 KB |
Output is correct |
11 |
Correct |
5 ms |
6636 KB |
Output is correct |
12 |
Correct |
4 ms |
6636 KB |
Output is correct |
13 |
Correct |
4 ms |
6636 KB |
Output is correct |
14 |
Correct |
5 ms |
6636 KB |
Output is correct |
15 |
Correct |
4 ms |
6636 KB |
Output is correct |
16 |
Correct |
4 ms |
6636 KB |
Output is correct |
17 |
Correct |
5 ms |
6636 KB |
Output is correct |
18 |
Correct |
4 ms |
6636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6636 KB |
Output is correct |
2 |
Correct |
4 ms |
6636 KB |
Output is correct |
3 |
Correct |
5 ms |
6636 KB |
Output is correct |
4 |
Correct |
4 ms |
6636 KB |
Output is correct |
5 |
Correct |
4 ms |
6636 KB |
Output is correct |
6 |
Correct |
5 ms |
6636 KB |
Output is correct |
7 |
Correct |
4 ms |
6636 KB |
Output is correct |
8 |
Correct |
4 ms |
6636 KB |
Output is correct |
9 |
Correct |
4 ms |
6636 KB |
Output is correct |
10 |
Correct |
5 ms |
6636 KB |
Output is correct |
11 |
Correct |
5 ms |
6636 KB |
Output is correct |
12 |
Correct |
4 ms |
6636 KB |
Output is correct |
13 |
Correct |
4 ms |
6636 KB |
Output is correct |
14 |
Correct |
5 ms |
6636 KB |
Output is correct |
15 |
Correct |
4 ms |
6636 KB |
Output is correct |
16 |
Correct |
4 ms |
6636 KB |
Output is correct |
17 |
Correct |
5 ms |
6636 KB |
Output is correct |
18 |
Correct |
4 ms |
6636 KB |
Output is correct |
19 |
Correct |
4 ms |
6636 KB |
Output is correct |
20 |
Correct |
5 ms |
6636 KB |
Output is correct |
21 |
Correct |
7 ms |
6764 KB |
Output is correct |
22 |
Correct |
7 ms |
6764 KB |
Output is correct |
23 |
Correct |
7 ms |
6764 KB |
Output is correct |
24 |
Correct |
7 ms |
6764 KB |
Output is correct |
25 |
Correct |
7 ms |
6764 KB |
Output is correct |
26 |
Correct |
6 ms |
6764 KB |
Output is correct |
27 |
Correct |
5 ms |
6636 KB |
Output is correct |
28 |
Correct |
7 ms |
6764 KB |
Output is correct |
29 |
Correct |
7 ms |
6764 KB |
Output is correct |
30 |
Correct |
7 ms |
6764 KB |
Output is correct |
31 |
Correct |
7 ms |
6764 KB |
Output is correct |
32 |
Correct |
7 ms |
6764 KB |
Output is correct |
33 |
Correct |
8 ms |
6764 KB |
Output is correct |
34 |
Correct |
7 ms |
6764 KB |
Output is correct |
35 |
Correct |
7 ms |
6764 KB |
Output is correct |
36 |
Correct |
7 ms |
6764 KB |
Output is correct |
37 |
Correct |
7 ms |
6764 KB |
Output is correct |
38 |
Correct |
9 ms |
6764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6636 KB |
Output is correct |
2 |
Correct |
4 ms |
6636 KB |
Output is correct |
3 |
Correct |
5 ms |
6636 KB |
Output is correct |
4 |
Correct |
4 ms |
6636 KB |
Output is correct |
5 |
Correct |
4 ms |
6636 KB |
Output is correct |
6 |
Correct |
5 ms |
6636 KB |
Output is correct |
7 |
Correct |
4 ms |
6636 KB |
Output is correct |
8 |
Correct |
4 ms |
6636 KB |
Output is correct |
9 |
Correct |
4 ms |
6636 KB |
Output is correct |
10 |
Correct |
5 ms |
6636 KB |
Output is correct |
11 |
Correct |
5 ms |
6636 KB |
Output is correct |
12 |
Correct |
4 ms |
6636 KB |
Output is correct |
13 |
Correct |
4 ms |
6636 KB |
Output is correct |
14 |
Correct |
5 ms |
6636 KB |
Output is correct |
15 |
Correct |
4 ms |
6636 KB |
Output is correct |
16 |
Correct |
4 ms |
6636 KB |
Output is correct |
17 |
Correct |
5 ms |
6636 KB |
Output is correct |
18 |
Correct |
4 ms |
6636 KB |
Output is correct |
19 |
Correct |
431 ms |
12296 KB |
Output is correct |
20 |
Correct |
417 ms |
12252 KB |
Output is correct |
21 |
Correct |
438 ms |
12400 KB |
Output is correct |
22 |
Correct |
349 ms |
12136 KB |
Output is correct |
23 |
Correct |
473 ms |
12376 KB |
Output is correct |
24 |
Correct |
231 ms |
12064 KB |
Output is correct |
25 |
Correct |
354 ms |
20708 KB |
Output is correct |
26 |
Correct |
190 ms |
21220 KB |
Output is correct |
27 |
Correct |
522 ms |
17004 KB |
Output is correct |
28 |
Correct |
1569 ms |
55596 KB |
Output is correct |
29 |
Correct |
1527 ms |
53964 KB |
Output is correct |
30 |
Correct |
523 ms |
19692 KB |
Output is correct |
31 |
Correct |
562 ms |
19564 KB |
Output is correct |
32 |
Correct |
631 ms |
19800 KB |
Output is correct |
33 |
Correct |
852 ms |
20072 KB |
Output is correct |
34 |
Correct |
1275 ms |
35040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
6636 KB |
Output is correct |
2 |
Correct |
4 ms |
6636 KB |
Output is correct |
3 |
Correct |
5 ms |
6636 KB |
Output is correct |
4 |
Correct |
4 ms |
6636 KB |
Output is correct |
5 |
Correct |
4 ms |
6636 KB |
Output is correct |
6 |
Correct |
5 ms |
6636 KB |
Output is correct |
7 |
Correct |
4 ms |
6636 KB |
Output is correct |
8 |
Correct |
4 ms |
6636 KB |
Output is correct |
9 |
Correct |
4 ms |
6636 KB |
Output is correct |
10 |
Correct |
5 ms |
6636 KB |
Output is correct |
11 |
Correct |
5 ms |
6636 KB |
Output is correct |
12 |
Correct |
4 ms |
6636 KB |
Output is correct |
13 |
Correct |
4 ms |
6636 KB |
Output is correct |
14 |
Correct |
5 ms |
6636 KB |
Output is correct |
15 |
Correct |
4 ms |
6636 KB |
Output is correct |
16 |
Correct |
4 ms |
6636 KB |
Output is correct |
17 |
Correct |
5 ms |
6636 KB |
Output is correct |
18 |
Correct |
4 ms |
6636 KB |
Output is correct |
19 |
Correct |
4 ms |
6636 KB |
Output is correct |
20 |
Correct |
5 ms |
6636 KB |
Output is correct |
21 |
Correct |
7 ms |
6764 KB |
Output is correct |
22 |
Correct |
7 ms |
6764 KB |
Output is correct |
23 |
Correct |
7 ms |
6764 KB |
Output is correct |
24 |
Correct |
7 ms |
6764 KB |
Output is correct |
25 |
Correct |
7 ms |
6764 KB |
Output is correct |
26 |
Correct |
6 ms |
6764 KB |
Output is correct |
27 |
Correct |
5 ms |
6636 KB |
Output is correct |
28 |
Correct |
7 ms |
6764 KB |
Output is correct |
29 |
Correct |
7 ms |
6764 KB |
Output is correct |
30 |
Correct |
7 ms |
6764 KB |
Output is correct |
31 |
Correct |
7 ms |
6764 KB |
Output is correct |
32 |
Correct |
7 ms |
6764 KB |
Output is correct |
33 |
Correct |
8 ms |
6764 KB |
Output is correct |
34 |
Correct |
7 ms |
6764 KB |
Output is correct |
35 |
Correct |
7 ms |
6764 KB |
Output is correct |
36 |
Correct |
7 ms |
6764 KB |
Output is correct |
37 |
Correct |
7 ms |
6764 KB |
Output is correct |
38 |
Correct |
9 ms |
6764 KB |
Output is correct |
39 |
Correct |
431 ms |
12296 KB |
Output is correct |
40 |
Correct |
417 ms |
12252 KB |
Output is correct |
41 |
Correct |
438 ms |
12400 KB |
Output is correct |
42 |
Correct |
349 ms |
12136 KB |
Output is correct |
43 |
Correct |
473 ms |
12376 KB |
Output is correct |
44 |
Correct |
231 ms |
12064 KB |
Output is correct |
45 |
Correct |
354 ms |
20708 KB |
Output is correct |
46 |
Correct |
190 ms |
21220 KB |
Output is correct |
47 |
Correct |
522 ms |
17004 KB |
Output is correct |
48 |
Correct |
1569 ms |
55596 KB |
Output is correct |
49 |
Correct |
1527 ms |
53964 KB |
Output is correct |
50 |
Correct |
523 ms |
19692 KB |
Output is correct |
51 |
Correct |
562 ms |
19564 KB |
Output is correct |
52 |
Correct |
631 ms |
19800 KB |
Output is correct |
53 |
Correct |
852 ms |
20072 KB |
Output is correct |
54 |
Correct |
1275 ms |
35040 KB |
Output is correct |
55 |
Correct |
43 ms |
8044 KB |
Output is correct |
56 |
Correct |
30 ms |
7404 KB |
Output is correct |
57 |
Correct |
265 ms |
13680 KB |
Output is correct |
58 |
Correct |
66 ms |
12768 KB |
Output is correct |
59 |
Correct |
637 ms |
35484 KB |
Output is correct |
60 |
Correct |
1884 ms |
69716 KB |
Output is correct |
61 |
Correct |
662 ms |
21356 KB |
Output is correct |
62 |
Correct |
544 ms |
19948 KB |
Output is correct |
63 |
Correct |
666 ms |
20076 KB |
Output is correct |
64 |
Correct |
2076 ms |
42048 KB |
Output is correct |
65 |
Correct |
1368 ms |
36772 KB |
Output is correct |
66 |
Correct |
1862 ms |
55992 KB |
Output is correct |
67 |
Correct |
216 ms |
20316 KB |
Output is correct |
68 |
Correct |
943 ms |
39068 KB |
Output is correct |
69 |
Correct |
932 ms |
39640 KB |
Output is correct |
70 |
Correct |
869 ms |
37988 KB |
Output is correct |