# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
551267 |
2022-04-20T07:53:43 Z |
AmShZ |
Race (IOI11_race) |
C++11 |
|
413 ms |
34200 KB |
//khodaya khodet komak kon
# include "race.h"
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <pii, int> ppi;
typedef pair <int, pii> pip;
typedef pair <pii, pii> ppp;
typedef pair <ll, ll> pll;
# define A first
# define B second
# define endl '\n'
# define sep ' '
# define all(x) x.begin(), x.end()
# define kill(x) return cout << x << endl, 0
# define SZ(x) int(x.size())
# define lc id << 1
# define rc id << 1 | 1
# define fast_io ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}
const int xn = 2e5 + 10;
const int xm = 1e6 + 10;
const int sq = 320;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const ld eps = 1e-15;
const int mod = 1e9 + 7;//998244353;
const int base = 257;
int sz[xn], ans = inf, a[xm], ptr, k;
pii b[xn];
bool hide[xn];
vector <pii> adj[xn];
void plant(int v, int p = - 1){
sz[v] = 1;
for (pii u : adj[v])
if (u.A != p && !hide[u.A])
plant(u.A, v), sz[v] += sz[u.A];
}
int find_centroid(int v, int s, int p = - 1){
for (pii u : adj[v])
if (u.A != p && !hide[u.A] && s < 2 * sz[u.A])
return find_centroid(u.A, s, v);
return v;
}
void DFS(int v, int p = - 1, int h = 0, int dis = 0){
if (k < dis)
return;
if (k == dis)
ans = min(ans, h);
else if (a[k - dis])
ans = min(ans, h + a[k - dis]);
b[ptr ++] = {dis, h};
for (pii u : adj[v])
if (u.A != p && !hide[u.A])
DFS(u.A, v, h + 1, dis + u.B);
}
void solve(int v){
plant(v);
v = find_centroid(v, sz[v]);
hide[v] = true;
vector <int> V;
for (pii u : adj[v]){
if (hide[u.A])
continue;
ptr = 0;
DFS(u.A, v, 1, u.B);
for (int i = 0; i < ptr; ++ i){
if (!a[b[i].A])
a[b[i].A] = inf;
a[b[i].A] = min(a[b[i].A], b[i].B);
V.push_back(b[i].A);
}
}
for (int x : V)
a[x] = 0;
for (pii u : adj[v])
if (!hide[u.A])
solve(u.A);
}
int best_path(int N, int K, int H[][2], int L[]){
k = K;
for (int i = 0; i < N - 1; ++ i){
int v = H[i][0], u = H[i][1], w = L[i];
adj[v].push_back({u, w});
adj[u].push_back({v, w});
}
solve(0);
if (ans == inf)
ans = - 1;
return ans;
}
/*
int main(){
fast_io;
count_routes();
return 0;
}
*/
/*
5 5 2
1 0
1 2
3 2
1 3
4 2
2
3 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
5036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
5036 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
5076 KB |
Output is correct |
22 |
Correct |
5 ms |
7508 KB |
Output is correct |
23 |
Correct |
4 ms |
7124 KB |
Output is correct |
24 |
Correct |
5 ms |
7992 KB |
Output is correct |
25 |
Correct |
4 ms |
6868 KB |
Output is correct |
26 |
Correct |
4 ms |
6356 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5844 KB |
Output is correct |
29 |
Correct |
4 ms |
6356 KB |
Output is correct |
30 |
Correct |
4 ms |
6484 KB |
Output is correct |
31 |
Correct |
4 ms |
6904 KB |
Output is correct |
32 |
Correct |
4 ms |
6868 KB |
Output is correct |
33 |
Correct |
5 ms |
7636 KB |
Output is correct |
34 |
Correct |
4 ms |
7252 KB |
Output is correct |
35 |
Correct |
5 ms |
8020 KB |
Output is correct |
36 |
Correct |
5 ms |
8336 KB |
Output is correct |
37 |
Correct |
4 ms |
6996 KB |
Output is correct |
38 |
Correct |
5 ms |
6228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
5036 KB |
Output is correct |
19 |
Correct |
102 ms |
10544 KB |
Output is correct |
20 |
Correct |
99 ms |
10512 KB |
Output is correct |
21 |
Correct |
104 ms |
10856 KB |
Output is correct |
22 |
Correct |
103 ms |
11412 KB |
Output is correct |
23 |
Correct |
74 ms |
10572 KB |
Output is correct |
24 |
Correct |
48 ms |
10496 KB |
Output is correct |
25 |
Correct |
102 ms |
14012 KB |
Output is correct |
26 |
Correct |
91 ms |
18872 KB |
Output is correct |
27 |
Correct |
142 ms |
15952 KB |
Output is correct |
28 |
Correct |
242 ms |
30212 KB |
Output is correct |
29 |
Correct |
236 ms |
29004 KB |
Output is correct |
30 |
Correct |
146 ms |
15952 KB |
Output is correct |
31 |
Correct |
158 ms |
15948 KB |
Output is correct |
32 |
Correct |
181 ms |
15828 KB |
Output is correct |
33 |
Correct |
181 ms |
14788 KB |
Output is correct |
34 |
Correct |
155 ms |
14668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4948 KB |
Output is correct |
7 |
Correct |
3 ms |
4948 KB |
Output is correct |
8 |
Correct |
3 ms |
4948 KB |
Output is correct |
9 |
Correct |
3 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
5036 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
4 ms |
5076 KB |
Output is correct |
22 |
Correct |
5 ms |
7508 KB |
Output is correct |
23 |
Correct |
4 ms |
7124 KB |
Output is correct |
24 |
Correct |
5 ms |
7992 KB |
Output is correct |
25 |
Correct |
4 ms |
6868 KB |
Output is correct |
26 |
Correct |
4 ms |
6356 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
4 ms |
5844 KB |
Output is correct |
29 |
Correct |
4 ms |
6356 KB |
Output is correct |
30 |
Correct |
4 ms |
6484 KB |
Output is correct |
31 |
Correct |
4 ms |
6904 KB |
Output is correct |
32 |
Correct |
4 ms |
6868 KB |
Output is correct |
33 |
Correct |
5 ms |
7636 KB |
Output is correct |
34 |
Correct |
4 ms |
7252 KB |
Output is correct |
35 |
Correct |
5 ms |
8020 KB |
Output is correct |
36 |
Correct |
5 ms |
8336 KB |
Output is correct |
37 |
Correct |
4 ms |
6996 KB |
Output is correct |
38 |
Correct |
5 ms |
6228 KB |
Output is correct |
39 |
Correct |
102 ms |
10544 KB |
Output is correct |
40 |
Correct |
99 ms |
10512 KB |
Output is correct |
41 |
Correct |
104 ms |
10856 KB |
Output is correct |
42 |
Correct |
103 ms |
11412 KB |
Output is correct |
43 |
Correct |
74 ms |
10572 KB |
Output is correct |
44 |
Correct |
48 ms |
10496 KB |
Output is correct |
45 |
Correct |
102 ms |
14012 KB |
Output is correct |
46 |
Correct |
91 ms |
18872 KB |
Output is correct |
47 |
Correct |
142 ms |
15952 KB |
Output is correct |
48 |
Correct |
242 ms |
30212 KB |
Output is correct |
49 |
Correct |
236 ms |
29004 KB |
Output is correct |
50 |
Correct |
146 ms |
15952 KB |
Output is correct |
51 |
Correct |
158 ms |
15948 KB |
Output is correct |
52 |
Correct |
181 ms |
15828 KB |
Output is correct |
53 |
Correct |
181 ms |
14788 KB |
Output is correct |
54 |
Correct |
155 ms |
14668 KB |
Output is correct |
55 |
Correct |
9 ms |
5628 KB |
Output is correct |
56 |
Correct |
10 ms |
5588 KB |
Output is correct |
57 |
Correct |
74 ms |
11548 KB |
Output is correct |
58 |
Correct |
31 ms |
11456 KB |
Output is correct |
59 |
Correct |
82 ms |
19264 KB |
Output is correct |
60 |
Correct |
328 ms |
34200 KB |
Output is correct |
61 |
Correct |
164 ms |
16148 KB |
Output is correct |
62 |
Correct |
167 ms |
16840 KB |
Output is correct |
63 |
Correct |
214 ms |
16824 KB |
Output is correct |
64 |
Correct |
413 ms |
19224 KB |
Output is correct |
65 |
Correct |
209 ms |
15748 KB |
Output is correct |
66 |
Correct |
309 ms |
30468 KB |
Output is correct |
67 |
Correct |
98 ms |
17880 KB |
Output is correct |
68 |
Correct |
206 ms |
19852 KB |
Output is correct |
69 |
Correct |
211 ms |
19920 KB |
Output is correct |
70 |
Correct |
204 ms |
19308 KB |
Output is correct |