# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
60114 |
2018-07-23T16:52:58 Z |
naderjemel |
Race (IOI11_race) |
C++14 |
|
1136 ms |
98020 KB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define MAX_N 200000
#define MAX_K 1000000
vector<vector<pair<int,int> > > adj;
int n,k,nn;
bool pross[MAX_N];
int sub[MAX_N],cnt;
int dist[MAX_K],book[MAX_K],bk,rs;
int dfs(int u, int p){nn++;
sub[u]=0;
for(pair<int,int> i:adj[u]){
if(!pross[i.first] && i.first!=p){
dfs(i.first,u);
sub[u]+=1+sub[i.first];
}
}
return sub[u];
}
int find(int u, int p){
for(pair<int,int> i:adj[u]){
if(!pross[i.fi] && i.fi!=p && sub[i.fi]>nn/2){
return find(i.fi,u);
}
}
return u;
}
void check(int u, int p, int ed, int d){
if(d>k) return;
if(book[k-d]==bk && dist[k-d]+ed<rs) rs=dist[k-d]+ed;
if(d==k && ed<rs) rs=ed;
for(pair<int,int> i:adj[u]){
if(!pross[i.fi] && i.fi!=p){
check(i.fi,u,ed+1,d+i.se);
}
}
}
void fill(int u, int p, int ed, int d){
if(d>k) return;
if(book[d]<bk){
book[d]=bk;
dist[d]=ed;
}
else dist[d]=min(ed,dist[d]);
for(pair<int,int> i:adj[u]){
if(!pross[i.fi] && i.fi!=p){
fill(i.fi,u,ed+1,d+i.se);
}
}
}
void solve(int u){nn=0;
dfs(u,-1);
if(sub[u]<=1) return;
int cnt=find(u,-1);
bk++;
for(pair<int,int> i:adj[cnt]){
if(!pross[i.fi]){
check(i.fi,cnt,1,i.se);
fill(i.fi,cnt,1,i.se);
}
}
pross[cnt]=true;
for(pair<int,int> i:adj[cnt]){
if(!pross[i.fi]){
solve(i.fi);
}
}
}
int best_path(int N, int K, int H[][2], int L[]){n=N; k=K;
adj.resize(N+2,vector<pair<int,int> >());
for(int i=0;i<N-1;i++){
adj[H[i][0]].push_back(make_pair(H[i][1],L[i]));
adj[H[i][1]].push_back(make_pair(H[i][0],L[i]));
}rs=1e9;
solve(0);
if(rs==1e9) return -1;
else return rs;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
612 KB |
Output is correct |
3 |
Correct |
3 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
724 KB |
Output is correct |
5 |
Correct |
4 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
756 KB |
Output is correct |
7 |
Correct |
4 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
848 KB |
Output is correct |
9 |
Correct |
3 ms |
848 KB |
Output is correct |
10 |
Correct |
2 ms |
848 KB |
Output is correct |
11 |
Correct |
3 ms |
848 KB |
Output is correct |
12 |
Correct |
4 ms |
848 KB |
Output is correct |
13 |
Correct |
3 ms |
848 KB |
Output is correct |
14 |
Correct |
3 ms |
920 KB |
Output is correct |
15 |
Correct |
3 ms |
920 KB |
Output is correct |
16 |
Correct |
2 ms |
920 KB |
Output is correct |
17 |
Correct |
3 ms |
920 KB |
Output is correct |
18 |
Correct |
3 ms |
920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
612 KB |
Output is correct |
3 |
Correct |
3 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
724 KB |
Output is correct |
5 |
Correct |
4 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
756 KB |
Output is correct |
7 |
Correct |
4 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
848 KB |
Output is correct |
9 |
Correct |
3 ms |
848 KB |
Output is correct |
10 |
Correct |
2 ms |
848 KB |
Output is correct |
11 |
Correct |
3 ms |
848 KB |
Output is correct |
12 |
Correct |
4 ms |
848 KB |
Output is correct |
13 |
Correct |
3 ms |
848 KB |
Output is correct |
14 |
Correct |
3 ms |
920 KB |
Output is correct |
15 |
Correct |
3 ms |
920 KB |
Output is correct |
16 |
Correct |
2 ms |
920 KB |
Output is correct |
17 |
Correct |
3 ms |
920 KB |
Output is correct |
18 |
Correct |
3 ms |
920 KB |
Output is correct |
19 |
Correct |
3 ms |
980 KB |
Output is correct |
20 |
Correct |
3 ms |
980 KB |
Output is correct |
21 |
Correct |
4 ms |
980 KB |
Output is correct |
22 |
Correct |
10 ms |
5856 KB |
Output is correct |
23 |
Correct |
9 ms |
5856 KB |
Output is correct |
24 |
Correct |
10 ms |
6612 KB |
Output is correct |
25 |
Correct |
8 ms |
6612 KB |
Output is correct |
26 |
Correct |
6 ms |
6612 KB |
Output is correct |
27 |
Correct |
4 ms |
6612 KB |
Output is correct |
28 |
Correct |
6 ms |
6612 KB |
Output is correct |
29 |
Correct |
6 ms |
6612 KB |
Output is correct |
30 |
Correct |
8 ms |
6612 KB |
Output is correct |
31 |
Correct |
7 ms |
6612 KB |
Output is correct |
32 |
Correct |
8 ms |
6612 KB |
Output is correct |
33 |
Correct |
10 ms |
6672 KB |
Output is correct |
34 |
Correct |
8 ms |
6672 KB |
Output is correct |
35 |
Correct |
11 ms |
7236 KB |
Output is correct |
36 |
Correct |
12 ms |
7852 KB |
Output is correct |
37 |
Correct |
10 ms |
7852 KB |
Output is correct |
38 |
Correct |
8 ms |
7852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
612 KB |
Output is correct |
3 |
Correct |
3 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
724 KB |
Output is correct |
5 |
Correct |
4 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
756 KB |
Output is correct |
7 |
Correct |
4 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
848 KB |
Output is correct |
9 |
Correct |
3 ms |
848 KB |
Output is correct |
10 |
Correct |
2 ms |
848 KB |
Output is correct |
11 |
Correct |
3 ms |
848 KB |
Output is correct |
12 |
Correct |
4 ms |
848 KB |
Output is correct |
13 |
Correct |
3 ms |
848 KB |
Output is correct |
14 |
Correct |
3 ms |
920 KB |
Output is correct |
15 |
Correct |
3 ms |
920 KB |
Output is correct |
16 |
Correct |
2 ms |
920 KB |
Output is correct |
17 |
Correct |
3 ms |
920 KB |
Output is correct |
18 |
Correct |
3 ms |
920 KB |
Output is correct |
19 |
Correct |
221 ms |
10356 KB |
Output is correct |
20 |
Correct |
241 ms |
11800 KB |
Output is correct |
21 |
Correct |
213 ms |
13056 KB |
Output is correct |
22 |
Correct |
268 ms |
14640 KB |
Output is correct |
23 |
Correct |
172 ms |
16176 KB |
Output is correct |
24 |
Correct |
144 ms |
17612 KB |
Output is correct |
25 |
Correct |
326 ms |
21448 KB |
Output is correct |
26 |
Correct |
164 ms |
25816 KB |
Output is correct |
27 |
Correct |
313 ms |
30848 KB |
Output is correct |
28 |
Correct |
559 ms |
45264 KB |
Output is correct |
29 |
Correct |
684 ms |
47468 KB |
Output is correct |
30 |
Correct |
308 ms |
47468 KB |
Output is correct |
31 |
Correct |
301 ms |
47468 KB |
Output is correct |
32 |
Correct |
403 ms |
47468 KB |
Output is correct |
33 |
Correct |
543 ms |
47764 KB |
Output is correct |
34 |
Correct |
495 ms |
51528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
612 KB |
Output is correct |
3 |
Correct |
3 ms |
724 KB |
Output is correct |
4 |
Correct |
3 ms |
724 KB |
Output is correct |
5 |
Correct |
4 ms |
724 KB |
Output is correct |
6 |
Correct |
3 ms |
756 KB |
Output is correct |
7 |
Correct |
4 ms |
760 KB |
Output is correct |
8 |
Correct |
2 ms |
848 KB |
Output is correct |
9 |
Correct |
3 ms |
848 KB |
Output is correct |
10 |
Correct |
2 ms |
848 KB |
Output is correct |
11 |
Correct |
3 ms |
848 KB |
Output is correct |
12 |
Correct |
4 ms |
848 KB |
Output is correct |
13 |
Correct |
3 ms |
848 KB |
Output is correct |
14 |
Correct |
3 ms |
920 KB |
Output is correct |
15 |
Correct |
3 ms |
920 KB |
Output is correct |
16 |
Correct |
2 ms |
920 KB |
Output is correct |
17 |
Correct |
3 ms |
920 KB |
Output is correct |
18 |
Correct |
3 ms |
920 KB |
Output is correct |
19 |
Correct |
3 ms |
980 KB |
Output is correct |
20 |
Correct |
3 ms |
980 KB |
Output is correct |
21 |
Correct |
4 ms |
980 KB |
Output is correct |
22 |
Correct |
10 ms |
5856 KB |
Output is correct |
23 |
Correct |
9 ms |
5856 KB |
Output is correct |
24 |
Correct |
10 ms |
6612 KB |
Output is correct |
25 |
Correct |
8 ms |
6612 KB |
Output is correct |
26 |
Correct |
6 ms |
6612 KB |
Output is correct |
27 |
Correct |
4 ms |
6612 KB |
Output is correct |
28 |
Correct |
6 ms |
6612 KB |
Output is correct |
29 |
Correct |
6 ms |
6612 KB |
Output is correct |
30 |
Correct |
8 ms |
6612 KB |
Output is correct |
31 |
Correct |
7 ms |
6612 KB |
Output is correct |
32 |
Correct |
8 ms |
6612 KB |
Output is correct |
33 |
Correct |
10 ms |
6672 KB |
Output is correct |
34 |
Correct |
8 ms |
6672 KB |
Output is correct |
35 |
Correct |
11 ms |
7236 KB |
Output is correct |
36 |
Correct |
12 ms |
7852 KB |
Output is correct |
37 |
Correct |
10 ms |
7852 KB |
Output is correct |
38 |
Correct |
8 ms |
7852 KB |
Output is correct |
39 |
Correct |
221 ms |
10356 KB |
Output is correct |
40 |
Correct |
241 ms |
11800 KB |
Output is correct |
41 |
Correct |
213 ms |
13056 KB |
Output is correct |
42 |
Correct |
268 ms |
14640 KB |
Output is correct |
43 |
Correct |
172 ms |
16176 KB |
Output is correct |
44 |
Correct |
144 ms |
17612 KB |
Output is correct |
45 |
Correct |
326 ms |
21448 KB |
Output is correct |
46 |
Correct |
164 ms |
25816 KB |
Output is correct |
47 |
Correct |
313 ms |
30848 KB |
Output is correct |
48 |
Correct |
559 ms |
45264 KB |
Output is correct |
49 |
Correct |
684 ms |
47468 KB |
Output is correct |
50 |
Correct |
308 ms |
47468 KB |
Output is correct |
51 |
Correct |
301 ms |
47468 KB |
Output is correct |
52 |
Correct |
403 ms |
47468 KB |
Output is correct |
53 |
Correct |
543 ms |
47764 KB |
Output is correct |
54 |
Correct |
495 ms |
51528 KB |
Output is correct |
55 |
Correct |
19 ms |
51528 KB |
Output is correct |
56 |
Correct |
19 ms |
51528 KB |
Output is correct |
57 |
Correct |
222 ms |
51528 KB |
Output is correct |
58 |
Correct |
69 ms |
51528 KB |
Output is correct |
59 |
Correct |
181 ms |
55408 KB |
Output is correct |
60 |
Correct |
1136 ms |
75152 KB |
Output is correct |
61 |
Correct |
284 ms |
75152 KB |
Output is correct |
62 |
Correct |
395 ms |
75152 KB |
Output is correct |
63 |
Correct |
491 ms |
75152 KB |
Output is correct |
64 |
Correct |
1041 ms |
75152 KB |
Output is correct |
65 |
Correct |
407 ms |
75920 KB |
Output is correct |
66 |
Correct |
985 ms |
95284 KB |
Output is correct |
67 |
Correct |
211 ms |
95284 KB |
Output is correct |
68 |
Correct |
438 ms |
95284 KB |
Output is correct |
69 |
Correct |
490 ms |
95592 KB |
Output is correct |
70 |
Correct |
456 ms |
98020 KB |
Output is correct |