# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
116273 |
2019-06-12T00:48:44 Z |
dragonslayerit |
Race (IOI11_race) |
C++14 |
|
3000 ms |
19360 KB |
#include "race.h"
#include <vector>
#include <map>
#include <stdint.h>
static const int INF=1e9+7;
static std::vector<std::pair<int,int> > adj[200005];
static int ans=INF;
static int size[200005];
static int KK;
static bool dead[200005];
static int dfs_size(int node,int parent){
size[node]=1;
for(auto e:adj[node]){
int child=e.first;
if(dead[child]||child==parent) continue;
dfs_size(child,node);
size[node]+=size[child];
}
}
static int find_centroid(int node,int parent,int total_size){
for(auto e:adj[node]){
int child=e.first;
if(dead[child]||child==parent) continue;
if(size[child]*2>total_size){
return find_centroid(child,node,total_size);
}
}
return node;
}
static void dfs_add(int node,int parent,int64_t dist,int len,std::map<int64_t,int>& best){
if(best.count(dist)){
best[dist]=std::min(best[dist],len);
}else{
best[dist]=len;
}
for(auto e:adj[node]){
int child=e.first;
if(dead[child]||child==parent) continue;
dfs_add(child,node,dist+e.second,len+1,best);
}
}
static void dfs_test(int node,int parent,int64_t dist,int len,std::map<int64_t,int>& best){
if(best.count(KK-dist)){
ans=std::min(ans,best[KK-dist]+len);
}
for(auto e:adj[node]){
int child=e.first;
if(dead[child]||child==parent) continue;
dfs_test(child,node,dist+e.second,len+1,best);
}
}
static void solve(int node){
dfs_size(node,node);
node=find_centroid(node,node,size[node]);
std::map<int64_t,int> best;
best[0]=0;
for(auto e:adj[node]){
int child=e.first;
dfs_test(child,node,e.second,1,best);
dfs_add(child,node,e.second,1,best);
}
dead[node]=true;
for(auto e:adj[node]){
int child=e.first;
if(dead[child]) continue;
solve(child);
}
}
int best_path(int N, int K, int H[][2], int L[])
{
for(int i=0;i<N;i++){
adj[i].clear();
}
ans=INF;
std::fill(dead,dead+N,false);
KK=K;
for(int i=0;i<N-1;i++){
adj[H[i][0]].emplace_back(H[i][1],L[i]);
adj[H[i][1]].emplace_back(H[i][0],L[i]);
}
solve(0);
return ans<INF?ans:-1;
}
Compilation message
race.cpp: In function 'int dfs_size(int, int)':
race.cpp:22:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5120 KB |
Output is correct |
2 |
Correct |
5 ms |
4992 KB |
Output is correct |
3 |
Correct |
5 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
5120 KB |
Output is correct |
7 |
Correct |
6 ms |
5120 KB |
Output is correct |
8 |
Correct |
6 ms |
5120 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
6 ms |
4992 KB |
Output is correct |
11 |
Correct |
6 ms |
5068 KB |
Output is correct |
12 |
Correct |
6 ms |
4992 KB |
Output is correct |
13 |
Correct |
6 ms |
5120 KB |
Output is correct |
14 |
Correct |
6 ms |
5120 KB |
Output is correct |
15 |
Correct |
6 ms |
5248 KB |
Output is correct |
16 |
Correct |
6 ms |
5120 KB |
Output is correct |
17 |
Correct |
5 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5120 KB |
Output is correct |
2 |
Correct |
5 ms |
4992 KB |
Output is correct |
3 |
Correct |
5 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
5120 KB |
Output is correct |
7 |
Correct |
6 ms |
5120 KB |
Output is correct |
8 |
Correct |
6 ms |
5120 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
6 ms |
4992 KB |
Output is correct |
11 |
Correct |
6 ms |
5068 KB |
Output is correct |
12 |
Correct |
6 ms |
4992 KB |
Output is correct |
13 |
Correct |
6 ms |
5120 KB |
Output is correct |
14 |
Correct |
6 ms |
5120 KB |
Output is correct |
15 |
Correct |
6 ms |
5248 KB |
Output is correct |
16 |
Correct |
6 ms |
5120 KB |
Output is correct |
17 |
Correct |
5 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
19 |
Correct |
6 ms |
4992 KB |
Output is correct |
20 |
Correct |
6 ms |
4988 KB |
Output is correct |
21 |
Correct |
8 ms |
5120 KB |
Output is correct |
22 |
Correct |
8 ms |
5248 KB |
Output is correct |
23 |
Correct |
9 ms |
5248 KB |
Output is correct |
24 |
Correct |
8 ms |
5248 KB |
Output is correct |
25 |
Correct |
8 ms |
5248 KB |
Output is correct |
26 |
Correct |
9 ms |
5248 KB |
Output is correct |
27 |
Correct |
6 ms |
5120 KB |
Output is correct |
28 |
Correct |
9 ms |
5248 KB |
Output is correct |
29 |
Correct |
8 ms |
5248 KB |
Output is correct |
30 |
Correct |
8 ms |
5248 KB |
Output is correct |
31 |
Correct |
8 ms |
5248 KB |
Output is correct |
32 |
Correct |
8 ms |
5248 KB |
Output is correct |
33 |
Correct |
9 ms |
5248 KB |
Output is correct |
34 |
Correct |
8 ms |
5248 KB |
Output is correct |
35 |
Correct |
8 ms |
5248 KB |
Output is correct |
36 |
Correct |
7 ms |
5248 KB |
Output is correct |
37 |
Correct |
7 ms |
5248 KB |
Output is correct |
38 |
Correct |
7 ms |
5248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5120 KB |
Output is correct |
2 |
Correct |
5 ms |
4992 KB |
Output is correct |
3 |
Correct |
5 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
5120 KB |
Output is correct |
7 |
Correct |
6 ms |
5120 KB |
Output is correct |
8 |
Correct |
6 ms |
5120 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
6 ms |
4992 KB |
Output is correct |
11 |
Correct |
6 ms |
5068 KB |
Output is correct |
12 |
Correct |
6 ms |
4992 KB |
Output is correct |
13 |
Correct |
6 ms |
5120 KB |
Output is correct |
14 |
Correct |
6 ms |
5120 KB |
Output is correct |
15 |
Correct |
6 ms |
5248 KB |
Output is correct |
16 |
Correct |
6 ms |
5120 KB |
Output is correct |
17 |
Correct |
5 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
19 |
Correct |
630 ms |
11924 KB |
Output is correct |
20 |
Correct |
609 ms |
11908 KB |
Output is correct |
21 |
Correct |
520 ms |
11896 KB |
Output is correct |
22 |
Correct |
553 ms |
11996 KB |
Output is correct |
23 |
Correct |
584 ms |
12688 KB |
Output is correct |
24 |
Correct |
501 ms |
12024 KB |
Output is correct |
25 |
Correct |
369 ms |
17784 KB |
Output is correct |
26 |
Correct |
137 ms |
17400 KB |
Output is correct |
27 |
Execution timed out |
3035 ms |
19360 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5120 KB |
Output is correct |
2 |
Correct |
5 ms |
4992 KB |
Output is correct |
3 |
Correct |
5 ms |
4992 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
5120 KB |
Output is correct |
7 |
Correct |
6 ms |
5120 KB |
Output is correct |
8 |
Correct |
6 ms |
5120 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
6 ms |
4992 KB |
Output is correct |
11 |
Correct |
6 ms |
5068 KB |
Output is correct |
12 |
Correct |
6 ms |
4992 KB |
Output is correct |
13 |
Correct |
6 ms |
5120 KB |
Output is correct |
14 |
Correct |
6 ms |
5120 KB |
Output is correct |
15 |
Correct |
6 ms |
5248 KB |
Output is correct |
16 |
Correct |
6 ms |
5120 KB |
Output is correct |
17 |
Correct |
5 ms |
4992 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
19 |
Correct |
6 ms |
4992 KB |
Output is correct |
20 |
Correct |
6 ms |
4988 KB |
Output is correct |
21 |
Correct |
8 ms |
5120 KB |
Output is correct |
22 |
Correct |
8 ms |
5248 KB |
Output is correct |
23 |
Correct |
9 ms |
5248 KB |
Output is correct |
24 |
Correct |
8 ms |
5248 KB |
Output is correct |
25 |
Correct |
8 ms |
5248 KB |
Output is correct |
26 |
Correct |
9 ms |
5248 KB |
Output is correct |
27 |
Correct |
6 ms |
5120 KB |
Output is correct |
28 |
Correct |
9 ms |
5248 KB |
Output is correct |
29 |
Correct |
8 ms |
5248 KB |
Output is correct |
30 |
Correct |
8 ms |
5248 KB |
Output is correct |
31 |
Correct |
8 ms |
5248 KB |
Output is correct |
32 |
Correct |
8 ms |
5248 KB |
Output is correct |
33 |
Correct |
9 ms |
5248 KB |
Output is correct |
34 |
Correct |
8 ms |
5248 KB |
Output is correct |
35 |
Correct |
8 ms |
5248 KB |
Output is correct |
36 |
Correct |
7 ms |
5248 KB |
Output is correct |
37 |
Correct |
7 ms |
5248 KB |
Output is correct |
38 |
Correct |
7 ms |
5248 KB |
Output is correct |
39 |
Correct |
630 ms |
11924 KB |
Output is correct |
40 |
Correct |
609 ms |
11908 KB |
Output is correct |
41 |
Correct |
520 ms |
11896 KB |
Output is correct |
42 |
Correct |
553 ms |
11996 KB |
Output is correct |
43 |
Correct |
584 ms |
12688 KB |
Output is correct |
44 |
Correct |
501 ms |
12024 KB |
Output is correct |
45 |
Correct |
369 ms |
17784 KB |
Output is correct |
46 |
Correct |
137 ms |
17400 KB |
Output is correct |
47 |
Execution timed out |
3035 ms |
19360 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |