Submission #919099

# Submission time Handle Problem Language Result Execution time Memory
919099 2024-01-31T08:58:07 Z Cutebol Race (IOI11_race) C++17
100 / 100
1016 ms 40020 KB
#include "race.h"
#include <bits/stdc++.h>
using namespace std ;
#define ff first 
#define ss second

const int Ne = 2e5 + 5 ;
const int inf = 1e9 ;

template <class T>
bool chmax( T& x , const T& y ){
  bool f = 0 ;
  if ( x < y ) x = y , f = 1 ;
  return f ;
}
template <class T>
bool chmin( T &x , const T &y ){
  bool f = 0 ;
  if ( x > y ) x = y , f = 1 ;
  return f ;
}

int n , k , ans = inf , sz[Ne] , mx ;
bool vis[Ne] ;
vector <int> mp ;
vector <pair <int , int>> g[Ne] ;
vector <pair <int , int>> vec ;

int fsz ( int v , int p = -1 ){
	sz[v] = 1 ;
	for ( auto to : g[v] ){
		if ( to.ff != p && !vis[to.ff] ) fsz(to.ff,v) , sz[v] += sz[to.ff] ;
	} return sz[v] ;
}

int centroid ( int v , int s , int p = -1 ){
	for ( auto to : g[v] ){
		if ( sz[to.ff] >= s && to.ff != p && !vis[to.ff] ) return centroid( to.ff , s , v ) ;
	} return v ;
}

void dfs( int v , int d , int s , int p ){
	if ( s > k ) return ;
	chmin ( ans , d+mp[k-s] ) ;
	chmax ( mx , s ) ;
	for ( auto to : g[v] ) if ( to.ff != p && !vis[to.ff] ) dfs( to.ff , d+1 , s+to.ss , v ) ;
}
void upd( int v , int d , int s , int p ){
	if ( s > k ) return ;
	chmin ( mp[s] , d ) ;
	for ( auto to : g[v] ) if ( to.ff != p && !vis[to.ff] ) upd( to.ff , d+1 , s+to.ss , v ) ;
}

void go ( int v ){
	v = centroid( v , fsz(v)/2 ) ;
	vis[v] = 1 ; mx = 0 ;
	for ( auto to : g[v] ){
		if ( vis[to.ff] ) continue ;
		dfs ( to.ff , 1 , to.ss , -1 ) ;
		upd ( to.ff , 1 , to.ss , -1 ) ;
	} chmin ( ans , mp[k] ) ;
	for ( int i = 0 ; i <= mx ; i ++ ) mp[i] = INT_MAX - n ;
	for ( auto to : g[v] ) if ( !vis[to.ff] ) go (to.ff) ;
}

int best_path(int N, int K, int h[][2], int l[]){
	n = N , k = K ;
	mp.resize(k+1 , INT_MAX-n);
	for ( int i = 0 ; i < n-1 ; 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) ;
	return (ans == inf) ? -1 : ans ;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8948 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8792 KB Output is correct
7 Correct 3 ms 8792 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 8792 KB Output is correct
10 Correct 2 ms 8792 KB Output is correct
11 Correct 2 ms 8792 KB Output is correct
12 Correct 2 ms 8792 KB Output is correct
13 Correct 2 ms 8792 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8780 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8528 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8948 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8792 KB Output is correct
7 Correct 3 ms 8792 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 8792 KB Output is correct
10 Correct 2 ms 8792 KB Output is correct
11 Correct 2 ms 8792 KB Output is correct
12 Correct 2 ms 8792 KB Output is correct
13 Correct 2 ms 8792 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8780 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8528 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8792 KB Output is correct
20 Correct 3 ms 9048 KB Output is correct
21 Correct 2 ms 8792 KB Output is correct
22 Correct 163 ms 12436 KB Output is correct
23 Correct 115 ms 11788 KB Output is correct
24 Correct 155 ms 12120 KB Output is correct
25 Correct 24 ms 12152 KB Output is correct
26 Correct 58 ms 10076 KB Output is correct
27 Correct 3 ms 11868 KB Output is correct
28 Correct 20 ms 9560 KB Output is correct
29 Correct 23 ms 10084 KB Output is correct
30 Correct 22 ms 10072 KB Output is correct
31 Correct 24 ms 11356 KB Output is correct
32 Correct 23 ms 11608 KB Output is correct
33 Correct 29 ms 11864 KB Output is correct
34 Correct 32 ms 11096 KB Output is correct
35 Correct 36 ms 11864 KB Output is correct
36 Correct 38 ms 12380 KB Output is correct
37 Correct 8 ms 11864 KB Output is correct
38 Correct 7 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8948 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8792 KB Output is correct
7 Correct 3 ms 8792 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 8792 KB Output is correct
10 Correct 2 ms 8792 KB Output is correct
11 Correct 2 ms 8792 KB Output is correct
12 Correct 2 ms 8792 KB Output is correct
13 Correct 2 ms 8792 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8780 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8528 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 82 ms 16392 KB Output is correct
20 Correct 78 ms 16488 KB Output is correct
21 Correct 84 ms 16464 KB Output is correct
22 Correct 83 ms 16860 KB Output is correct
23 Correct 47 ms 16772 KB Output is correct
24 Correct 37 ms 16720 KB Output is correct
25 Correct 81 ms 20076 KB Output is correct
26 Correct 70 ms 23888 KB Output is correct
27 Correct 110 ms 22352 KB Output is correct
28 Correct 193 ms 36856 KB Output is correct
29 Correct 195 ms 35672 KB Output is correct
30 Correct 118 ms 22356 KB Output is correct
31 Correct 129 ms 22592 KB Output is correct
32 Correct 152 ms 22436 KB Output is correct
33 Correct 151 ms 21568 KB Output is correct
34 Correct 116 ms 22096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8948 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8792 KB Output is correct
7 Correct 3 ms 8792 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 8792 KB Output is correct
10 Correct 2 ms 8792 KB Output is correct
11 Correct 2 ms 8792 KB Output is correct
12 Correct 2 ms 8792 KB Output is correct
13 Correct 2 ms 8792 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8780 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8528 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8792 KB Output is correct
20 Correct 3 ms 9048 KB Output is correct
21 Correct 2 ms 8792 KB Output is correct
22 Correct 163 ms 12436 KB Output is correct
23 Correct 115 ms 11788 KB Output is correct
24 Correct 155 ms 12120 KB Output is correct
25 Correct 24 ms 12152 KB Output is correct
26 Correct 58 ms 10076 KB Output is correct
27 Correct 3 ms 11868 KB Output is correct
28 Correct 20 ms 9560 KB Output is correct
29 Correct 23 ms 10084 KB Output is correct
30 Correct 22 ms 10072 KB Output is correct
31 Correct 24 ms 11356 KB Output is correct
32 Correct 23 ms 11608 KB Output is correct
33 Correct 29 ms 11864 KB Output is correct
34 Correct 32 ms 11096 KB Output is correct
35 Correct 36 ms 11864 KB Output is correct
36 Correct 38 ms 12380 KB Output is correct
37 Correct 8 ms 11864 KB Output is correct
38 Correct 7 ms 10840 KB Output is correct
39 Correct 82 ms 16392 KB Output is correct
40 Correct 78 ms 16488 KB Output is correct
41 Correct 84 ms 16464 KB Output is correct
42 Correct 83 ms 16860 KB Output is correct
43 Correct 47 ms 16772 KB Output is correct
44 Correct 37 ms 16720 KB Output is correct
45 Correct 81 ms 20076 KB Output is correct
46 Correct 70 ms 23888 KB Output is correct
47 Correct 110 ms 22352 KB Output is correct
48 Correct 193 ms 36856 KB Output is correct
49 Correct 195 ms 35672 KB Output is correct
50 Correct 118 ms 22356 KB Output is correct
51 Correct 129 ms 22592 KB Output is correct
52 Correct 152 ms 22436 KB Output is correct
53 Correct 151 ms 21568 KB Output is correct
54 Correct 116 ms 22096 KB Output is correct
55 Correct 10 ms 9304 KB Output is correct
56 Correct 9 ms 9304 KB Output is correct
57 Correct 49 ms 16724 KB Output is correct
58 Correct 26 ms 16324 KB Output is correct
59 Correct 72 ms 24400 KB Output is correct
60 Correct 330 ms 40020 KB Output is correct
61 Correct 135 ms 22608 KB Output is correct
62 Correct 143 ms 26452 KB Output is correct
63 Correct 195 ms 26472 KB Output is correct
64 Correct 1016 ms 24656 KB Output is correct
65 Correct 118 ms 23124 KB Output is correct
66 Correct 563 ms 37244 KB Output is correct
67 Correct 76 ms 27072 KB Output is correct
68 Correct 327 ms 27216 KB Output is correct
69 Correct 299 ms 27096 KB Output is correct
70 Correct 285 ms 26960 KB Output is correct