# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
245920 |
2020-07-07T19:31:10 Z |
oscarsierra12 |
Race (IOI11_race) |
C++14 |
|
2124 ms |
53352 KB |
#include "race.h"
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string.h>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <set>
#include <deque>
#include <utility>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <math.h>
#include <algorithm>
#include <limits.h>
using namespace std ;
#define ff first
#define ss second
#define pb push_back
const int MAX_N = 3e5+2 ;
typedef pair<int,int> ii ;
vector <ii> G[MAX_N];
int depth[MAX_N];
int sz[MAX_N] ;
int ans = 1e9+7 ;
int k ;
int visit[MAX_N];
void calc ( int u, int p, int d ) {
depth[u] = d ;
sz[u] = 1;
for ( auto v:G[u] ) {
if ( visit[v.ff] || v.ff == p) continue ;
calc ( v.ff, u, d+1 ) ;
sz[u] += sz[v.ff] ;
}
}
int centroid ( int u, int p, int el ) {
int ok = 1, x = -1 ;
for ( auto v:G[u] ) {
if ( visit[v.ff] ) continue ;
if ( v.ff!=p ) {
// cout << el/2 << ' ' << v.ff << ' ' << sz[v.ff] << endl ;
ok &= (sz[v.ff] <= el/2) ;
x = max ( x, centroid(v.ff, u, el) ) ;
}
}
if ( ok && (el-sz[u]) <= el/2 ) x = max (x, u) ;
return x ;
}
map <int, int> mp ;
vector <ii> car ;
void doit ( int u, int p, int val ) {
if ( mp[k-val] != 0 ) ans = min ( ans, mp[k-val] + depth[u] - 2 ) ;
car.push_back ({val, depth[u]}) ;
for ( auto v:G[u] ) {
if ( v.ff==p || visit[v.ff] ) continue ;
doit ( v.ff, u, min ( 1000010, val + v.ss ) ) ;
}
}
int go ( int u ) {
calc ( u, -1, 1 ) ;
int root = centroid ( u, -1, sz[u] ) ;
//cout << "centroid = " << root << endl ;
calc ( root, -1, 1 ) ;
mp[0] = 1 ;
for ( auto v:G[root] ) {
if ( visit[v.ff] ) continue ;
doit ( v.ff, root, v.ss ) ;
for ( auto i:car ) {
if ( mp[i.ff] == 0 ) mp[i.ff] = i.ss ;
mp[i.ff] = min ( mp[i.ff], i.ss ) ;
}
car.clear() ;
}
mp.clear() ;
visit[root] = 1 ;
for ( auto v:G[root] ) {
if ( visit[v.ff] ) continue ;
go ( v.ff ) ;
}
}
int best_path(int N, int K, int H[][2], int L[])
{
k = K ;
for ( int i = 0 ; i+1 < N ;++i ) {
G[H[i][0]].push_back ( {H[i][1], L[i]} ) ;
G[H[i][1]].push_back ( {H[i][0], L[i]} ) ;
}
go ( 0 ) ;
if ( ans > MAX_N ) ans = -1 ;
return ans;
}
Compilation message
race.cpp: In function 'int go(int)':
race.cpp:96:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
9 ms |
7424 KB |
Output is correct |
3 |
Correct |
10 ms |
7424 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
9 ms |
7424 KB |
Output is correct |
6 |
Correct |
9 ms |
7424 KB |
Output is correct |
7 |
Correct |
9 ms |
7424 KB |
Output is correct |
8 |
Correct |
9 ms |
7424 KB |
Output is correct |
9 |
Correct |
8 ms |
7424 KB |
Output is correct |
10 |
Correct |
9 ms |
7424 KB |
Output is correct |
11 |
Correct |
9 ms |
7424 KB |
Output is correct |
12 |
Correct |
9 ms |
7424 KB |
Output is correct |
13 |
Correct |
9 ms |
7424 KB |
Output is correct |
14 |
Correct |
9 ms |
7424 KB |
Output is correct |
15 |
Correct |
9 ms |
7424 KB |
Output is correct |
16 |
Correct |
9 ms |
7424 KB |
Output is correct |
17 |
Correct |
9 ms |
7424 KB |
Output is correct |
18 |
Correct |
9 ms |
7424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
9 ms |
7424 KB |
Output is correct |
3 |
Correct |
10 ms |
7424 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
9 ms |
7424 KB |
Output is correct |
6 |
Correct |
9 ms |
7424 KB |
Output is correct |
7 |
Correct |
9 ms |
7424 KB |
Output is correct |
8 |
Correct |
9 ms |
7424 KB |
Output is correct |
9 |
Correct |
8 ms |
7424 KB |
Output is correct |
10 |
Correct |
9 ms |
7424 KB |
Output is correct |
11 |
Correct |
9 ms |
7424 KB |
Output is correct |
12 |
Correct |
9 ms |
7424 KB |
Output is correct |
13 |
Correct |
9 ms |
7424 KB |
Output is correct |
14 |
Correct |
9 ms |
7424 KB |
Output is correct |
15 |
Correct |
9 ms |
7424 KB |
Output is correct |
16 |
Correct |
9 ms |
7424 KB |
Output is correct |
17 |
Correct |
9 ms |
7424 KB |
Output is correct |
18 |
Correct |
9 ms |
7424 KB |
Output is correct |
19 |
Correct |
8 ms |
7424 KB |
Output is correct |
20 |
Correct |
9 ms |
7424 KB |
Output is correct |
21 |
Correct |
11 ms |
7552 KB |
Output is correct |
22 |
Correct |
10 ms |
7424 KB |
Output is correct |
23 |
Correct |
10 ms |
7424 KB |
Output is correct |
24 |
Correct |
10 ms |
7552 KB |
Output is correct |
25 |
Correct |
12 ms |
7552 KB |
Output is correct |
26 |
Correct |
12 ms |
7552 KB |
Output is correct |
27 |
Correct |
10 ms |
7424 KB |
Output is correct |
28 |
Correct |
12 ms |
7552 KB |
Output is correct |
29 |
Correct |
15 ms |
7552 KB |
Output is correct |
30 |
Correct |
12 ms |
7552 KB |
Output is correct |
31 |
Correct |
11 ms |
7552 KB |
Output is correct |
32 |
Correct |
11 ms |
7552 KB |
Output is correct |
33 |
Correct |
12 ms |
7552 KB |
Output is correct |
34 |
Correct |
11 ms |
7424 KB |
Output is correct |
35 |
Correct |
11 ms |
7424 KB |
Output is correct |
36 |
Correct |
13 ms |
7552 KB |
Output is correct |
37 |
Correct |
11 ms |
7552 KB |
Output is correct |
38 |
Correct |
12 ms |
7552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
9 ms |
7424 KB |
Output is correct |
3 |
Correct |
10 ms |
7424 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
9 ms |
7424 KB |
Output is correct |
6 |
Correct |
9 ms |
7424 KB |
Output is correct |
7 |
Correct |
9 ms |
7424 KB |
Output is correct |
8 |
Correct |
9 ms |
7424 KB |
Output is correct |
9 |
Correct |
8 ms |
7424 KB |
Output is correct |
10 |
Correct |
9 ms |
7424 KB |
Output is correct |
11 |
Correct |
9 ms |
7424 KB |
Output is correct |
12 |
Correct |
9 ms |
7424 KB |
Output is correct |
13 |
Correct |
9 ms |
7424 KB |
Output is correct |
14 |
Correct |
9 ms |
7424 KB |
Output is correct |
15 |
Correct |
9 ms |
7424 KB |
Output is correct |
16 |
Correct |
9 ms |
7424 KB |
Output is correct |
17 |
Correct |
9 ms |
7424 KB |
Output is correct |
18 |
Correct |
9 ms |
7424 KB |
Output is correct |
19 |
Correct |
495 ms |
15220 KB |
Output is correct |
20 |
Correct |
441 ms |
15224 KB |
Output is correct |
21 |
Correct |
560 ms |
15228 KB |
Output is correct |
22 |
Correct |
353 ms |
15344 KB |
Output is correct |
23 |
Correct |
587 ms |
15496 KB |
Output is correct |
24 |
Correct |
243 ms |
15236 KB |
Output is correct |
25 |
Correct |
336 ms |
19784 KB |
Output is correct |
26 |
Correct |
169 ms |
22648 KB |
Output is correct |
27 |
Correct |
556 ms |
23032 KB |
Output is correct |
28 |
Correct |
1893 ms |
41452 KB |
Output is correct |
29 |
Correct |
1815 ms |
40300 KB |
Output is correct |
30 |
Correct |
550 ms |
22776 KB |
Output is correct |
31 |
Correct |
543 ms |
22904 KB |
Output is correct |
32 |
Correct |
676 ms |
23032 KB |
Output is correct |
33 |
Correct |
975 ms |
22420 KB |
Output is correct |
34 |
Correct |
611 ms |
23020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
9 ms |
7424 KB |
Output is correct |
3 |
Correct |
10 ms |
7424 KB |
Output is correct |
4 |
Correct |
9 ms |
7424 KB |
Output is correct |
5 |
Correct |
9 ms |
7424 KB |
Output is correct |
6 |
Correct |
9 ms |
7424 KB |
Output is correct |
7 |
Correct |
9 ms |
7424 KB |
Output is correct |
8 |
Correct |
9 ms |
7424 KB |
Output is correct |
9 |
Correct |
8 ms |
7424 KB |
Output is correct |
10 |
Correct |
9 ms |
7424 KB |
Output is correct |
11 |
Correct |
9 ms |
7424 KB |
Output is correct |
12 |
Correct |
9 ms |
7424 KB |
Output is correct |
13 |
Correct |
9 ms |
7424 KB |
Output is correct |
14 |
Correct |
9 ms |
7424 KB |
Output is correct |
15 |
Correct |
9 ms |
7424 KB |
Output is correct |
16 |
Correct |
9 ms |
7424 KB |
Output is correct |
17 |
Correct |
9 ms |
7424 KB |
Output is correct |
18 |
Correct |
9 ms |
7424 KB |
Output is correct |
19 |
Correct |
8 ms |
7424 KB |
Output is correct |
20 |
Correct |
9 ms |
7424 KB |
Output is correct |
21 |
Correct |
11 ms |
7552 KB |
Output is correct |
22 |
Correct |
10 ms |
7424 KB |
Output is correct |
23 |
Correct |
10 ms |
7424 KB |
Output is correct |
24 |
Correct |
10 ms |
7552 KB |
Output is correct |
25 |
Correct |
12 ms |
7552 KB |
Output is correct |
26 |
Correct |
12 ms |
7552 KB |
Output is correct |
27 |
Correct |
10 ms |
7424 KB |
Output is correct |
28 |
Correct |
12 ms |
7552 KB |
Output is correct |
29 |
Correct |
15 ms |
7552 KB |
Output is correct |
30 |
Correct |
12 ms |
7552 KB |
Output is correct |
31 |
Correct |
11 ms |
7552 KB |
Output is correct |
32 |
Correct |
11 ms |
7552 KB |
Output is correct |
33 |
Correct |
12 ms |
7552 KB |
Output is correct |
34 |
Correct |
11 ms |
7424 KB |
Output is correct |
35 |
Correct |
11 ms |
7424 KB |
Output is correct |
36 |
Correct |
13 ms |
7552 KB |
Output is correct |
37 |
Correct |
11 ms |
7552 KB |
Output is correct |
38 |
Correct |
12 ms |
7552 KB |
Output is correct |
39 |
Correct |
495 ms |
15220 KB |
Output is correct |
40 |
Correct |
441 ms |
15224 KB |
Output is correct |
41 |
Correct |
560 ms |
15228 KB |
Output is correct |
42 |
Correct |
353 ms |
15344 KB |
Output is correct |
43 |
Correct |
587 ms |
15496 KB |
Output is correct |
44 |
Correct |
243 ms |
15236 KB |
Output is correct |
45 |
Correct |
336 ms |
19784 KB |
Output is correct |
46 |
Correct |
169 ms |
22648 KB |
Output is correct |
47 |
Correct |
556 ms |
23032 KB |
Output is correct |
48 |
Correct |
1893 ms |
41452 KB |
Output is correct |
49 |
Correct |
1815 ms |
40300 KB |
Output is correct |
50 |
Correct |
550 ms |
22776 KB |
Output is correct |
51 |
Correct |
543 ms |
22904 KB |
Output is correct |
52 |
Correct |
676 ms |
23032 KB |
Output is correct |
53 |
Correct |
975 ms |
22420 KB |
Output is correct |
54 |
Correct |
611 ms |
23020 KB |
Output is correct |
55 |
Correct |
49 ms |
8832 KB |
Output is correct |
56 |
Correct |
33 ms |
8192 KB |
Output is correct |
57 |
Correct |
260 ms |
15428 KB |
Output is correct |
58 |
Correct |
68 ms |
14828 KB |
Output is correct |
59 |
Correct |
609 ms |
29168 KB |
Output is correct |
60 |
Correct |
1984 ms |
53352 KB |
Output is correct |
61 |
Correct |
652 ms |
25336 KB |
Output is correct |
62 |
Correct |
580 ms |
22904 KB |
Output is correct |
63 |
Correct |
798 ms |
23076 KB |
Output is correct |
64 |
Correct |
2124 ms |
32748 KB |
Output is correct |
65 |
Correct |
744 ms |
24308 KB |
Output is correct |
66 |
Correct |
1526 ms |
34800 KB |
Output is correct |
67 |
Correct |
202 ms |
23400 KB |
Output is correct |
68 |
Correct |
890 ms |
31468 KB |
Output is correct |
69 |
Correct |
875 ms |
31596 KB |
Output is correct |
70 |
Correct |
875 ms |
30572 KB |
Output is correct |