# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
63116 |
2018-07-31T20:25:23 Z |
FLDutchman |
Race (IOI11_race) |
C++14 |
|
2422 ms |
101000 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
typedef int INT;
#define int long long
#define pb push_back
#define fst first
#define snd second
#define FOR(i, l, r) for(int i = (l); i < (r); i++)
#define V vector
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
struct edge {int v, l;};
int N, K;
V<V<edge>> adj;
V<bool> used;
int centroid(int u, int par, int &root, int size){
//if(u == par) cout << "calling centroid " << u << " " << size << endl;
int sz = 1;
int ma = 0;
for(edge e : adj[u]) if(!used[e.v] and e.v != par) {
int s = centroid(e.v, u, root, size);
sz += s;
ma = max(ma, s);
}
//if(size != 0)
// cout << "largest " << max(ma, size-sz) << endl;
if(max(ma, size-sz) <= size/2) root = u;
//if(size != 0) cout << u << " " << par << " " << sz << endl;
return sz;
}
void dfs(int u, int par, int d, int l, vii &paths){
//cout << "dfs " << u << " " << par << endl;
paths.pb({d, l});
for(edge e : adj[u]) if(!used[e.v] and e.v != par) dfs(e.v, u, d+e.l, l+1, paths);
}
int shortest(int u){
//cout << "shortest " << u << endl;
int root, sz;
sz = centroid(u, u, root, 0);
centroid(u, u, root, sz);
//cout << "root " << root << " " << sz << endl;
used[root] = 1;
map<int, int> paths;
int best = 1e9;
for(edge e : adj[root]) if(!used[e.v]) {
vii pa;
dfs(e.v, root, e.l, 1, pa);
for(ii p : pa){
int &l = paths[ K - p.fst ];
if(l != 0) best = min(best, p.snd + l);
if(p.fst == K) best = min(best, p.snd);
}
for(ii p : pa){
int &l = paths[p.fst];
if(l == 0) l = p.snd;
else l = min(l, p.snd);
}
}
for(edge e : adj[root]) if(!used[e.v]) best = min(best, shortest(e.v));
return best;
}
INT best_path(INT n, INT k, INT H[][2], INT L[]) {
N = n; K = k;
adj.resize(N);
used.assign(N, 0);
FOR(i, 0, N-1) {
//if(L[i] + L[i+1] == K) {cerr << i << endl; return 2;}
adj[H[i][0]].pb({H[i][1], L[i]});
adj[H[i][1]].pb({H[i][0], L[i]});
}
int res = shortest(0);
return res == 1e9 ? -1 : res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
3 ms |
412 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
3 ms |
428 KB |
Output is correct |
6 |
Correct |
2 ms |
428 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
484 KB |
Output is correct |
9 |
Correct |
2 ms |
484 KB |
Output is correct |
10 |
Correct |
4 ms |
544 KB |
Output is correct |
11 |
Correct |
4 ms |
548 KB |
Output is correct |
12 |
Correct |
4 ms |
680 KB |
Output is correct |
13 |
Correct |
4 ms |
680 KB |
Output is correct |
14 |
Correct |
3 ms |
680 KB |
Output is correct |
15 |
Correct |
3 ms |
680 KB |
Output is correct |
16 |
Correct |
3 ms |
680 KB |
Output is correct |
17 |
Correct |
5 ms |
680 KB |
Output is correct |
18 |
Correct |
3 ms |
712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
3 ms |
412 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
3 ms |
428 KB |
Output is correct |
6 |
Correct |
2 ms |
428 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
484 KB |
Output is correct |
9 |
Correct |
2 ms |
484 KB |
Output is correct |
10 |
Correct |
4 ms |
544 KB |
Output is correct |
11 |
Correct |
4 ms |
548 KB |
Output is correct |
12 |
Correct |
4 ms |
680 KB |
Output is correct |
13 |
Correct |
4 ms |
680 KB |
Output is correct |
14 |
Correct |
3 ms |
680 KB |
Output is correct |
15 |
Correct |
3 ms |
680 KB |
Output is correct |
16 |
Correct |
3 ms |
680 KB |
Output is correct |
17 |
Correct |
5 ms |
680 KB |
Output is correct |
18 |
Correct |
3 ms |
712 KB |
Output is correct |
19 |
Correct |
2 ms |
712 KB |
Output is correct |
20 |
Correct |
3 ms |
712 KB |
Output is correct |
21 |
Correct |
5 ms |
748 KB |
Output is correct |
22 |
Correct |
7 ms |
888 KB |
Output is correct |
23 |
Correct |
7 ms |
904 KB |
Output is correct |
24 |
Correct |
7 ms |
920 KB |
Output is correct |
25 |
Correct |
6 ms |
936 KB |
Output is correct |
26 |
Correct |
6 ms |
956 KB |
Output is correct |
27 |
Correct |
4 ms |
956 KB |
Output is correct |
28 |
Correct |
7 ms |
996 KB |
Output is correct |
29 |
Correct |
7 ms |
1068 KB |
Output is correct |
30 |
Correct |
6 ms |
1192 KB |
Output is correct |
31 |
Correct |
6 ms |
1192 KB |
Output is correct |
32 |
Correct |
6 ms |
1192 KB |
Output is correct |
33 |
Correct |
6 ms |
1192 KB |
Output is correct |
34 |
Correct |
8 ms |
1192 KB |
Output is correct |
35 |
Correct |
6 ms |
1192 KB |
Output is correct |
36 |
Correct |
6 ms |
1192 KB |
Output is correct |
37 |
Correct |
8 ms |
1192 KB |
Output is correct |
38 |
Correct |
5 ms |
1196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
3 ms |
412 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
3 ms |
428 KB |
Output is correct |
6 |
Correct |
2 ms |
428 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
484 KB |
Output is correct |
9 |
Correct |
2 ms |
484 KB |
Output is correct |
10 |
Correct |
4 ms |
544 KB |
Output is correct |
11 |
Correct |
4 ms |
548 KB |
Output is correct |
12 |
Correct |
4 ms |
680 KB |
Output is correct |
13 |
Correct |
4 ms |
680 KB |
Output is correct |
14 |
Correct |
3 ms |
680 KB |
Output is correct |
15 |
Correct |
3 ms |
680 KB |
Output is correct |
16 |
Correct |
3 ms |
680 KB |
Output is correct |
17 |
Correct |
5 ms |
680 KB |
Output is correct |
18 |
Correct |
3 ms |
712 KB |
Output is correct |
19 |
Correct |
591 ms |
12528 KB |
Output is correct |
20 |
Correct |
575 ms |
13776 KB |
Output is correct |
21 |
Correct |
483 ms |
15404 KB |
Output is correct |
22 |
Correct |
600 ms |
16188 KB |
Output is correct |
23 |
Correct |
690 ms |
17908 KB |
Output is correct |
24 |
Correct |
282 ms |
18356 KB |
Output is correct |
25 |
Correct |
398 ms |
26876 KB |
Output is correct |
26 |
Correct |
257 ms |
31320 KB |
Output is correct |
27 |
Correct |
568 ms |
33292 KB |
Output is correct |
28 |
Correct |
2076 ms |
101000 KB |
Output is correct |
29 |
Correct |
2422 ms |
101000 KB |
Output is correct |
30 |
Correct |
580 ms |
101000 KB |
Output is correct |
31 |
Correct |
647 ms |
101000 KB |
Output is correct |
32 |
Correct |
723 ms |
101000 KB |
Output is correct |
33 |
Correct |
1324 ms |
101000 KB |
Output is correct |
34 |
Correct |
2416 ms |
101000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
3 ms |
412 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
3 ms |
428 KB |
Output is correct |
6 |
Correct |
2 ms |
428 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
484 KB |
Output is correct |
9 |
Correct |
2 ms |
484 KB |
Output is correct |
10 |
Correct |
4 ms |
544 KB |
Output is correct |
11 |
Correct |
4 ms |
548 KB |
Output is correct |
12 |
Correct |
4 ms |
680 KB |
Output is correct |
13 |
Correct |
4 ms |
680 KB |
Output is correct |
14 |
Correct |
3 ms |
680 KB |
Output is correct |
15 |
Correct |
3 ms |
680 KB |
Output is correct |
16 |
Correct |
3 ms |
680 KB |
Output is correct |
17 |
Correct |
5 ms |
680 KB |
Output is correct |
18 |
Correct |
3 ms |
712 KB |
Output is correct |
19 |
Correct |
2 ms |
712 KB |
Output is correct |
20 |
Correct |
3 ms |
712 KB |
Output is correct |
21 |
Correct |
5 ms |
748 KB |
Output is correct |
22 |
Correct |
7 ms |
888 KB |
Output is correct |
23 |
Correct |
7 ms |
904 KB |
Output is correct |
24 |
Correct |
7 ms |
920 KB |
Output is correct |
25 |
Correct |
6 ms |
936 KB |
Output is correct |
26 |
Correct |
6 ms |
956 KB |
Output is correct |
27 |
Correct |
4 ms |
956 KB |
Output is correct |
28 |
Correct |
7 ms |
996 KB |
Output is correct |
29 |
Correct |
7 ms |
1068 KB |
Output is correct |
30 |
Correct |
6 ms |
1192 KB |
Output is correct |
31 |
Correct |
6 ms |
1192 KB |
Output is correct |
32 |
Correct |
6 ms |
1192 KB |
Output is correct |
33 |
Correct |
6 ms |
1192 KB |
Output is correct |
34 |
Correct |
8 ms |
1192 KB |
Output is correct |
35 |
Correct |
6 ms |
1192 KB |
Output is correct |
36 |
Correct |
6 ms |
1192 KB |
Output is correct |
37 |
Correct |
8 ms |
1192 KB |
Output is correct |
38 |
Correct |
5 ms |
1196 KB |
Output is correct |
39 |
Correct |
591 ms |
12528 KB |
Output is correct |
40 |
Correct |
575 ms |
13776 KB |
Output is correct |
41 |
Correct |
483 ms |
15404 KB |
Output is correct |
42 |
Correct |
600 ms |
16188 KB |
Output is correct |
43 |
Correct |
690 ms |
17908 KB |
Output is correct |
44 |
Correct |
282 ms |
18356 KB |
Output is correct |
45 |
Correct |
398 ms |
26876 KB |
Output is correct |
46 |
Correct |
257 ms |
31320 KB |
Output is correct |
47 |
Correct |
568 ms |
33292 KB |
Output is correct |
48 |
Correct |
2076 ms |
101000 KB |
Output is correct |
49 |
Correct |
2422 ms |
101000 KB |
Output is correct |
50 |
Correct |
580 ms |
101000 KB |
Output is correct |
51 |
Correct |
647 ms |
101000 KB |
Output is correct |
52 |
Correct |
723 ms |
101000 KB |
Output is correct |
53 |
Correct |
1324 ms |
101000 KB |
Output is correct |
54 |
Correct |
2416 ms |
101000 KB |
Output is correct |
55 |
Correct |
47 ms |
101000 KB |
Output is correct |
56 |
Correct |
33 ms |
101000 KB |
Output is correct |
57 |
Correct |
277 ms |
101000 KB |
Output is correct |
58 |
Correct |
111 ms |
101000 KB |
Output is correct |
59 |
Correct |
850 ms |
101000 KB |
Output is correct |
60 |
Correct |
2410 ms |
101000 KB |
Output is correct |
61 |
Correct |
776 ms |
101000 KB |
Output is correct |
62 |
Correct |
744 ms |
101000 KB |
Output is correct |
63 |
Correct |
792 ms |
101000 KB |
Output is correct |
64 |
Correct |
2353 ms |
101000 KB |
Output is correct |
65 |
Correct |
2344 ms |
101000 KB |
Output is correct |
66 |
Correct |
2322 ms |
101000 KB |
Output is correct |
67 |
Correct |
229 ms |
101000 KB |
Output is correct |
68 |
Correct |
1383 ms |
101000 KB |
Output is correct |
69 |
Correct |
1300 ms |
101000 KB |
Output is correct |
70 |
Correct |
1078 ms |
101000 KB |
Output is correct |