# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
302451 |
2020-09-18T17:13:14 Z |
Hemimor |
Race (IOI11_race) |
C++14 |
|
992 ms |
40440 KB |
#include "race.h"
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vp;
typedef vector<vp> vvp;
const int inf=1<<30,MAX=1000001,NMAX=200000;
int res=inf,c[MAX],s[NMAX];
ll m;
bool vis[NMAX];
vp g[NMAX];
int Cdfs(int v,int p){
s[v]=1;
for(auto i:g[v]){
int u=i.first;
if(!vis[u]&&u!=p) s[v]+=Cdfs(u,v);
}
return s[v];
}
P Cdfs1(int v,int p,int S){
P q={inf,0};
int M=0,S_=S-1;
for(auto i:g[v]){
int u=i.first;
if(!vis[u]&&u!=p){
q=min(q,Cdfs1(u,v,S));
M=max(M,s[u]);
S_-=s[u];
}
}
return min(q,{max(M,S_),v});
}
int Cent(int v){
Cdfs(v,-1);
return Cdfs1(v,-1,s[v]).second;
}
int t,len,tp;
void DFS(int v,int par=-1){
if(len>=res||t>m) return;
if(t==m) res=min(res,len);
if(tp==1) c[t]=min(c[t],len);
else if(tp==2) c[t]=inf;
else if(t<m) res=min(res,c[m-t]+len);
for(auto p:g[v]){
int u=p.first;
if(!vis[u]&&u!=par){
len++;
t+=p.second;
DFS(u,v);
len--;
t-=p.second;
}
}
}
void Rec(int v){
v=Cent(v);
vis[v]=1;
for(auto p:g[v]){
int u=p.first;
if(!vis[u]){
t=p.second,len=1,tp=0;
DFS(u);
t=p.second,len=1,tp=1;
DFS(u);
}
}
for(auto p:g[v]){
int u=p.first;
if(!vis[u]){
t=p.second,len=1,tp=2;
DFS(u);
}
}
for(auto p:g[v]){
int u=p.first;
if(!vis[u]) Rec(u);
}
}
int best_path(int N, int K, int H[][2], int L[]){
m=K;
fill(c,c+MAX,inf);
for(int i=0;i<N-1;i++){
int u=H[i][0],v=H[i][1];
g[u].push_back({v,L[i]});
g[v].push_back({u,L[i]});
}
Rec(0);
if(res==inf) res=-1;
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8960 KB |
Output is correct |
2 |
Correct |
6 ms |
8960 KB |
Output is correct |
3 |
Correct |
6 ms |
8960 KB |
Output is correct |
4 |
Correct |
6 ms |
8960 KB |
Output is correct |
5 |
Correct |
6 ms |
8960 KB |
Output is correct |
6 |
Correct |
6 ms |
8960 KB |
Output is correct |
7 |
Correct |
6 ms |
8960 KB |
Output is correct |
8 |
Correct |
6 ms |
8960 KB |
Output is correct |
9 |
Correct |
6 ms |
8960 KB |
Output is correct |
10 |
Correct |
6 ms |
8960 KB |
Output is correct |
11 |
Correct |
6 ms |
8960 KB |
Output is correct |
12 |
Correct |
6 ms |
8960 KB |
Output is correct |
13 |
Correct |
6 ms |
8960 KB |
Output is correct |
14 |
Correct |
6 ms |
8960 KB |
Output is correct |
15 |
Correct |
6 ms |
8960 KB |
Output is correct |
16 |
Correct |
6 ms |
8960 KB |
Output is correct |
17 |
Correct |
6 ms |
8960 KB |
Output is correct |
18 |
Correct |
6 ms |
8960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8960 KB |
Output is correct |
2 |
Correct |
6 ms |
8960 KB |
Output is correct |
3 |
Correct |
6 ms |
8960 KB |
Output is correct |
4 |
Correct |
6 ms |
8960 KB |
Output is correct |
5 |
Correct |
6 ms |
8960 KB |
Output is correct |
6 |
Correct |
6 ms |
8960 KB |
Output is correct |
7 |
Correct |
6 ms |
8960 KB |
Output is correct |
8 |
Correct |
6 ms |
8960 KB |
Output is correct |
9 |
Correct |
6 ms |
8960 KB |
Output is correct |
10 |
Correct |
6 ms |
8960 KB |
Output is correct |
11 |
Correct |
6 ms |
8960 KB |
Output is correct |
12 |
Correct |
6 ms |
8960 KB |
Output is correct |
13 |
Correct |
6 ms |
8960 KB |
Output is correct |
14 |
Correct |
6 ms |
8960 KB |
Output is correct |
15 |
Correct |
6 ms |
8960 KB |
Output is correct |
16 |
Correct |
6 ms |
8960 KB |
Output is correct |
17 |
Correct |
6 ms |
8960 KB |
Output is correct |
18 |
Correct |
6 ms |
8960 KB |
Output is correct |
19 |
Correct |
6 ms |
8960 KB |
Output is correct |
20 |
Correct |
6 ms |
8960 KB |
Output is correct |
21 |
Correct |
7 ms |
8960 KB |
Output is correct |
22 |
Correct |
7 ms |
8960 KB |
Output is correct |
23 |
Correct |
7 ms |
8960 KB |
Output is correct |
24 |
Correct |
7 ms |
8960 KB |
Output is correct |
25 |
Correct |
8 ms |
8960 KB |
Output is correct |
26 |
Correct |
7 ms |
9088 KB |
Output is correct |
27 |
Correct |
7 ms |
9088 KB |
Output is correct |
28 |
Correct |
8 ms |
8960 KB |
Output is correct |
29 |
Correct |
7 ms |
8960 KB |
Output is correct |
30 |
Correct |
7 ms |
8960 KB |
Output is correct |
31 |
Correct |
7 ms |
8960 KB |
Output is correct |
32 |
Correct |
7 ms |
8960 KB |
Output is correct |
33 |
Correct |
8 ms |
8960 KB |
Output is correct |
34 |
Correct |
7 ms |
8960 KB |
Output is correct |
35 |
Correct |
7 ms |
8960 KB |
Output is correct |
36 |
Correct |
7 ms |
9088 KB |
Output is correct |
37 |
Correct |
7 ms |
8960 KB |
Output is correct |
38 |
Correct |
7 ms |
8960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8960 KB |
Output is correct |
2 |
Correct |
6 ms |
8960 KB |
Output is correct |
3 |
Correct |
6 ms |
8960 KB |
Output is correct |
4 |
Correct |
6 ms |
8960 KB |
Output is correct |
5 |
Correct |
6 ms |
8960 KB |
Output is correct |
6 |
Correct |
6 ms |
8960 KB |
Output is correct |
7 |
Correct |
6 ms |
8960 KB |
Output is correct |
8 |
Correct |
6 ms |
8960 KB |
Output is correct |
9 |
Correct |
6 ms |
8960 KB |
Output is correct |
10 |
Correct |
6 ms |
8960 KB |
Output is correct |
11 |
Correct |
6 ms |
8960 KB |
Output is correct |
12 |
Correct |
6 ms |
8960 KB |
Output is correct |
13 |
Correct |
6 ms |
8960 KB |
Output is correct |
14 |
Correct |
6 ms |
8960 KB |
Output is correct |
15 |
Correct |
6 ms |
8960 KB |
Output is correct |
16 |
Correct |
6 ms |
8960 KB |
Output is correct |
17 |
Correct |
6 ms |
8960 KB |
Output is correct |
18 |
Correct |
6 ms |
8960 KB |
Output is correct |
19 |
Correct |
193 ms |
14328 KB |
Output is correct |
20 |
Correct |
190 ms |
14200 KB |
Output is correct |
21 |
Correct |
200 ms |
14456 KB |
Output is correct |
22 |
Correct |
208 ms |
14328 KB |
Output is correct |
23 |
Correct |
135 ms |
14460 KB |
Output is correct |
24 |
Correct |
92 ms |
14584 KB |
Output is correct |
25 |
Correct |
195 ms |
19448 KB |
Output is correct |
26 |
Correct |
150 ms |
24824 KB |
Output is correct |
27 |
Correct |
243 ms |
19832 KB |
Output is correct |
28 |
Correct |
433 ms |
40440 KB |
Output is correct |
29 |
Correct |
437 ms |
38780 KB |
Output is correct |
30 |
Correct |
239 ms |
19832 KB |
Output is correct |
31 |
Correct |
250 ms |
19964 KB |
Output is correct |
32 |
Correct |
309 ms |
19832 KB |
Output is correct |
33 |
Correct |
377 ms |
18808 KB |
Output is correct |
34 |
Correct |
375 ms |
18808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8960 KB |
Output is correct |
2 |
Correct |
6 ms |
8960 KB |
Output is correct |
3 |
Correct |
6 ms |
8960 KB |
Output is correct |
4 |
Correct |
6 ms |
8960 KB |
Output is correct |
5 |
Correct |
6 ms |
8960 KB |
Output is correct |
6 |
Correct |
6 ms |
8960 KB |
Output is correct |
7 |
Correct |
6 ms |
8960 KB |
Output is correct |
8 |
Correct |
6 ms |
8960 KB |
Output is correct |
9 |
Correct |
6 ms |
8960 KB |
Output is correct |
10 |
Correct |
6 ms |
8960 KB |
Output is correct |
11 |
Correct |
6 ms |
8960 KB |
Output is correct |
12 |
Correct |
6 ms |
8960 KB |
Output is correct |
13 |
Correct |
6 ms |
8960 KB |
Output is correct |
14 |
Correct |
6 ms |
8960 KB |
Output is correct |
15 |
Correct |
6 ms |
8960 KB |
Output is correct |
16 |
Correct |
6 ms |
8960 KB |
Output is correct |
17 |
Correct |
6 ms |
8960 KB |
Output is correct |
18 |
Correct |
6 ms |
8960 KB |
Output is correct |
19 |
Correct |
6 ms |
8960 KB |
Output is correct |
20 |
Correct |
6 ms |
8960 KB |
Output is correct |
21 |
Correct |
7 ms |
8960 KB |
Output is correct |
22 |
Correct |
7 ms |
8960 KB |
Output is correct |
23 |
Correct |
7 ms |
8960 KB |
Output is correct |
24 |
Correct |
7 ms |
8960 KB |
Output is correct |
25 |
Correct |
8 ms |
8960 KB |
Output is correct |
26 |
Correct |
7 ms |
9088 KB |
Output is correct |
27 |
Correct |
7 ms |
9088 KB |
Output is correct |
28 |
Correct |
8 ms |
8960 KB |
Output is correct |
29 |
Correct |
7 ms |
8960 KB |
Output is correct |
30 |
Correct |
7 ms |
8960 KB |
Output is correct |
31 |
Correct |
7 ms |
8960 KB |
Output is correct |
32 |
Correct |
7 ms |
8960 KB |
Output is correct |
33 |
Correct |
8 ms |
8960 KB |
Output is correct |
34 |
Correct |
7 ms |
8960 KB |
Output is correct |
35 |
Correct |
7 ms |
8960 KB |
Output is correct |
36 |
Correct |
7 ms |
9088 KB |
Output is correct |
37 |
Correct |
7 ms |
8960 KB |
Output is correct |
38 |
Correct |
7 ms |
8960 KB |
Output is correct |
39 |
Correct |
193 ms |
14328 KB |
Output is correct |
40 |
Correct |
190 ms |
14200 KB |
Output is correct |
41 |
Correct |
200 ms |
14456 KB |
Output is correct |
42 |
Correct |
208 ms |
14328 KB |
Output is correct |
43 |
Correct |
135 ms |
14460 KB |
Output is correct |
44 |
Correct |
92 ms |
14584 KB |
Output is correct |
45 |
Correct |
195 ms |
19448 KB |
Output is correct |
46 |
Correct |
150 ms |
24824 KB |
Output is correct |
47 |
Correct |
243 ms |
19832 KB |
Output is correct |
48 |
Correct |
433 ms |
40440 KB |
Output is correct |
49 |
Correct |
437 ms |
38780 KB |
Output is correct |
50 |
Correct |
239 ms |
19832 KB |
Output is correct |
51 |
Correct |
250 ms |
19964 KB |
Output is correct |
52 |
Correct |
309 ms |
19832 KB |
Output is correct |
53 |
Correct |
377 ms |
18808 KB |
Output is correct |
54 |
Correct |
375 ms |
18808 KB |
Output is correct |
55 |
Correct |
19 ms |
9472 KB |
Output is correct |
56 |
Correct |
19 ms |
9472 KB |
Output is correct |
57 |
Correct |
127 ms |
14456 KB |
Output is correct |
58 |
Correct |
53 ms |
14572 KB |
Output is correct |
59 |
Correct |
150 ms |
25208 KB |
Output is correct |
60 |
Correct |
720 ms |
40184 KB |
Output is correct |
61 |
Correct |
277 ms |
20472 KB |
Output is correct |
62 |
Correct |
299 ms |
20344 KB |
Output is correct |
63 |
Correct |
440 ms |
20472 KB |
Output is correct |
64 |
Correct |
992 ms |
20216 KB |
Output is correct |
65 |
Correct |
442 ms |
20344 KB |
Output is correct |
66 |
Correct |
609 ms |
35576 KB |
Output is correct |
67 |
Correct |
155 ms |
20580 KB |
Output is correct |
68 |
Correct |
305 ms |
20472 KB |
Output is correct |
69 |
Correct |
340 ms |
20512 KB |
Output is correct |
70 |
Correct |
288 ms |
20088 KB |
Output is correct |