# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
857743 |
2023-10-06T19:23:30 Z |
tigran |
Race (IOI11_race) |
C++17 |
|
1258 ms |
56416 KB |
#include <bits/stdc++.h>
#define pb push_back
#include "race.h"
#define endl "\n"
#define fastio cin.tie(0); ios_base::sync_with_stdio(false);
typedef long long ll;
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 2e5 + 5;
vector<pair<int, int> > adj[MAXN];
vector<int> sub(MAXN), vis(MAXN);
inline void subtreecalc(int node, int par){
sub[node] = 1;
for(auto itr: adj[node]){
if(itr.first != par && !vis[itr.first]){
subtreecalc(itr.first, node);
sub[node] += sub[itr.first];
}
}
}
inline int find_centroid(int node, int par, int sz){
for(auto itr: adj[node]){
if(vis[itr.first] || itr.first == par) continue;
if(sub[itr.first] > sz/2) return find_centroid(itr.first, node, sz);
}
return node;
}
inline void dfs(int node, int par, int depth, int len, map<int, int> &mpp){
if(vis[node]) return;
if(!mpp[depth]) mpp[depth] = len;
else mpp[depth] = min(mpp[depth], len);
for(auto itr: adj[node]){
if(vis[itr.first] || itr.first == par) continue;
dfs(itr.first, node, depth + itr.second, len + 1, mpp);
}
}
bool compare(pair<int, int> p1, pair<int, int> p2){
return (sub[p1.first] > sub[p2.first]);
}
int best_path(int N, int K, int H[][2], int L[]){
for(int i = 0; i < N-1; i++){
adj[H[i][0]].pb({H[i][1], L[i]});
adj[H[i][1]].pb({H[i][0], L[i]});
}
int ans = 1e9;
vector<int> roots, new_roots;
roots.pb(0);
int cnt = 0;
while(cnt < N){
for(auto i: roots) subtreecalc(i, i);
for(auto i: roots){
int ct = find_centroid(i, i, sub[i]);
sort(adj[ct].begin(), adj[ct].end(), compare);
int ind = 0;
map<int, int> pre, now;
while(ind < adj[ct].size()){
if(vis[adj[ct][ind].first]){
ind++;
continue;
}
dfs(adj[ct][ind].first, ct, adj[ct][ind].second, 1, now);
for(auto itr: now){
if(pre[K - itr.first]) ans = min(ans, pre[K - itr.first] + now[itr.first]);
if(itr.first == K) ans = min(ans, itr.second);
}
for(auto itr: now){
if(!pre[itr.first] && itr.first != 0) pre[itr.first] = itr.second;
else pre[itr.first] = min(pre[itr.first], now[itr.first]);
}
now.clear();
ind++;
}
vis[ct] = 1;
for(auto itr: adj[ct]){
if(!vis[itr.first]) new_roots.pb(itr.first);
}
cnt++;
}
roots = new_roots;
new_roots.clear();
}
if(ans == 1e9) return -1;
else return ans;
}
Compilation message
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:67:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | while(ind < adj[ct].size()){
| ~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10332 KB |
Output is correct |
2 |
Correct |
2 ms |
10332 KB |
Output is correct |
3 |
Correct |
2 ms |
10332 KB |
Output is correct |
4 |
Correct |
3 ms |
10372 KB |
Output is correct |
5 |
Correct |
2 ms |
10332 KB |
Output is correct |
6 |
Correct |
2 ms |
10332 KB |
Output is correct |
7 |
Correct |
2 ms |
10332 KB |
Output is correct |
8 |
Correct |
3 ms |
10332 KB |
Output is correct |
9 |
Correct |
3 ms |
10332 KB |
Output is correct |
10 |
Correct |
2 ms |
10584 KB |
Output is correct |
11 |
Correct |
2 ms |
10332 KB |
Output is correct |
12 |
Correct |
2 ms |
10332 KB |
Output is correct |
13 |
Correct |
2 ms |
10168 KB |
Output is correct |
14 |
Correct |
2 ms |
10328 KB |
Output is correct |
15 |
Correct |
2 ms |
10332 KB |
Output is correct |
16 |
Correct |
2 ms |
10328 KB |
Output is correct |
17 |
Correct |
2 ms |
10332 KB |
Output is correct |
18 |
Correct |
2 ms |
10332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10332 KB |
Output is correct |
2 |
Correct |
2 ms |
10332 KB |
Output is correct |
3 |
Correct |
2 ms |
10332 KB |
Output is correct |
4 |
Correct |
3 ms |
10372 KB |
Output is correct |
5 |
Correct |
2 ms |
10332 KB |
Output is correct |
6 |
Correct |
2 ms |
10332 KB |
Output is correct |
7 |
Correct |
2 ms |
10332 KB |
Output is correct |
8 |
Correct |
3 ms |
10332 KB |
Output is correct |
9 |
Correct |
3 ms |
10332 KB |
Output is correct |
10 |
Correct |
2 ms |
10584 KB |
Output is correct |
11 |
Correct |
2 ms |
10332 KB |
Output is correct |
12 |
Correct |
2 ms |
10332 KB |
Output is correct |
13 |
Correct |
2 ms |
10168 KB |
Output is correct |
14 |
Correct |
2 ms |
10328 KB |
Output is correct |
15 |
Correct |
2 ms |
10332 KB |
Output is correct |
16 |
Correct |
2 ms |
10328 KB |
Output is correct |
17 |
Correct |
2 ms |
10332 KB |
Output is correct |
18 |
Correct |
2 ms |
10332 KB |
Output is correct |
19 |
Correct |
3 ms |
10328 KB |
Output is correct |
20 |
Correct |
3 ms |
10328 KB |
Output is correct |
21 |
Correct |
4 ms |
10328 KB |
Output is correct |
22 |
Correct |
5 ms |
10332 KB |
Output is correct |
23 |
Correct |
5 ms |
10332 KB |
Output is correct |
24 |
Correct |
4 ms |
10332 KB |
Output is correct |
25 |
Correct |
5 ms |
10452 KB |
Output is correct |
26 |
Correct |
4 ms |
10332 KB |
Output is correct |
27 |
Correct |
3 ms |
10388 KB |
Output is correct |
28 |
Correct |
4 ms |
10424 KB |
Output is correct |
29 |
Correct |
5 ms |
10332 KB |
Output is correct |
30 |
Correct |
5 ms |
10320 KB |
Output is correct |
31 |
Correct |
4 ms |
10332 KB |
Output is correct |
32 |
Correct |
4 ms |
10328 KB |
Output is correct |
33 |
Correct |
5 ms |
10332 KB |
Output is correct |
34 |
Correct |
5 ms |
10328 KB |
Output is correct |
35 |
Correct |
4 ms |
10332 KB |
Output is correct |
36 |
Correct |
4 ms |
10384 KB |
Output is correct |
37 |
Correct |
4 ms |
10332 KB |
Output is correct |
38 |
Correct |
4 ms |
10332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10332 KB |
Output is correct |
2 |
Correct |
2 ms |
10332 KB |
Output is correct |
3 |
Correct |
2 ms |
10332 KB |
Output is correct |
4 |
Correct |
3 ms |
10372 KB |
Output is correct |
5 |
Correct |
2 ms |
10332 KB |
Output is correct |
6 |
Correct |
2 ms |
10332 KB |
Output is correct |
7 |
Correct |
2 ms |
10332 KB |
Output is correct |
8 |
Correct |
3 ms |
10332 KB |
Output is correct |
9 |
Correct |
3 ms |
10332 KB |
Output is correct |
10 |
Correct |
2 ms |
10584 KB |
Output is correct |
11 |
Correct |
2 ms |
10332 KB |
Output is correct |
12 |
Correct |
2 ms |
10332 KB |
Output is correct |
13 |
Correct |
2 ms |
10168 KB |
Output is correct |
14 |
Correct |
2 ms |
10328 KB |
Output is correct |
15 |
Correct |
2 ms |
10332 KB |
Output is correct |
16 |
Correct |
2 ms |
10328 KB |
Output is correct |
17 |
Correct |
2 ms |
10332 KB |
Output is correct |
18 |
Correct |
2 ms |
10332 KB |
Output is correct |
19 |
Correct |
217 ms |
17660 KB |
Output is correct |
20 |
Correct |
216 ms |
17864 KB |
Output is correct |
21 |
Correct |
201 ms |
17964 KB |
Output is correct |
22 |
Correct |
210 ms |
17980 KB |
Output is correct |
23 |
Correct |
340 ms |
18424 KB |
Output is correct |
24 |
Correct |
177 ms |
18636 KB |
Output is correct |
25 |
Correct |
169 ms |
23280 KB |
Output is correct |
26 |
Correct |
77 ms |
22908 KB |
Output is correct |
27 |
Correct |
329 ms |
23412 KB |
Output is correct |
28 |
Correct |
1246 ms |
56292 KB |
Output is correct |
29 |
Correct |
1141 ms |
56168 KB |
Output is correct |
30 |
Correct |
378 ms |
23608 KB |
Output is correct |
31 |
Correct |
331 ms |
23380 KB |
Output is correct |
32 |
Correct |
366 ms |
23704 KB |
Output is correct |
33 |
Correct |
546 ms |
22496 KB |
Output is correct |
34 |
Correct |
1036 ms |
44248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10332 KB |
Output is correct |
2 |
Correct |
2 ms |
10332 KB |
Output is correct |
3 |
Correct |
2 ms |
10332 KB |
Output is correct |
4 |
Correct |
3 ms |
10372 KB |
Output is correct |
5 |
Correct |
2 ms |
10332 KB |
Output is correct |
6 |
Correct |
2 ms |
10332 KB |
Output is correct |
7 |
Correct |
2 ms |
10332 KB |
Output is correct |
8 |
Correct |
3 ms |
10332 KB |
Output is correct |
9 |
Correct |
3 ms |
10332 KB |
Output is correct |
10 |
Correct |
2 ms |
10584 KB |
Output is correct |
11 |
Correct |
2 ms |
10332 KB |
Output is correct |
12 |
Correct |
2 ms |
10332 KB |
Output is correct |
13 |
Correct |
2 ms |
10168 KB |
Output is correct |
14 |
Correct |
2 ms |
10328 KB |
Output is correct |
15 |
Correct |
2 ms |
10332 KB |
Output is correct |
16 |
Correct |
2 ms |
10328 KB |
Output is correct |
17 |
Correct |
2 ms |
10332 KB |
Output is correct |
18 |
Correct |
2 ms |
10332 KB |
Output is correct |
19 |
Correct |
3 ms |
10328 KB |
Output is correct |
20 |
Correct |
3 ms |
10328 KB |
Output is correct |
21 |
Correct |
4 ms |
10328 KB |
Output is correct |
22 |
Correct |
5 ms |
10332 KB |
Output is correct |
23 |
Correct |
5 ms |
10332 KB |
Output is correct |
24 |
Correct |
4 ms |
10332 KB |
Output is correct |
25 |
Correct |
5 ms |
10452 KB |
Output is correct |
26 |
Correct |
4 ms |
10332 KB |
Output is correct |
27 |
Correct |
3 ms |
10388 KB |
Output is correct |
28 |
Correct |
4 ms |
10424 KB |
Output is correct |
29 |
Correct |
5 ms |
10332 KB |
Output is correct |
30 |
Correct |
5 ms |
10320 KB |
Output is correct |
31 |
Correct |
4 ms |
10332 KB |
Output is correct |
32 |
Correct |
4 ms |
10328 KB |
Output is correct |
33 |
Correct |
5 ms |
10332 KB |
Output is correct |
34 |
Correct |
5 ms |
10328 KB |
Output is correct |
35 |
Correct |
4 ms |
10332 KB |
Output is correct |
36 |
Correct |
4 ms |
10384 KB |
Output is correct |
37 |
Correct |
4 ms |
10332 KB |
Output is correct |
38 |
Correct |
4 ms |
10332 KB |
Output is correct |
39 |
Correct |
217 ms |
17660 KB |
Output is correct |
40 |
Correct |
216 ms |
17864 KB |
Output is correct |
41 |
Correct |
201 ms |
17964 KB |
Output is correct |
42 |
Correct |
210 ms |
17980 KB |
Output is correct |
43 |
Correct |
340 ms |
18424 KB |
Output is correct |
44 |
Correct |
177 ms |
18636 KB |
Output is correct |
45 |
Correct |
169 ms |
23280 KB |
Output is correct |
46 |
Correct |
77 ms |
22908 KB |
Output is correct |
47 |
Correct |
329 ms |
23412 KB |
Output is correct |
48 |
Correct |
1246 ms |
56292 KB |
Output is correct |
49 |
Correct |
1141 ms |
56168 KB |
Output is correct |
50 |
Correct |
378 ms |
23608 KB |
Output is correct |
51 |
Correct |
331 ms |
23380 KB |
Output is correct |
52 |
Correct |
366 ms |
23704 KB |
Output is correct |
53 |
Correct |
546 ms |
22496 KB |
Output is correct |
54 |
Correct |
1036 ms |
44248 KB |
Output is correct |
55 |
Correct |
32 ms |
11608 KB |
Output is correct |
56 |
Correct |
15 ms |
10840 KB |
Output is correct |
57 |
Correct |
122 ms |
18200 KB |
Output is correct |
58 |
Correct |
46 ms |
18276 KB |
Output is correct |
59 |
Correct |
455 ms |
31568 KB |
Output is correct |
60 |
Correct |
1196 ms |
53712 KB |
Output is correct |
61 |
Correct |
415 ms |
25852 KB |
Output is correct |
62 |
Correct |
330 ms |
23676 KB |
Output is correct |
63 |
Correct |
403 ms |
23832 KB |
Output is correct |
64 |
Correct |
1106 ms |
34132 KB |
Output is correct |
65 |
Correct |
965 ms |
42484 KB |
Output is correct |
66 |
Correct |
1258 ms |
56416 KB |
Output is correct |
67 |
Correct |
103 ms |
25536 KB |
Output is correct |
68 |
Correct |
545 ms |
39612 KB |
Output is correct |
69 |
Correct |
520 ms |
40108 KB |
Output is correct |
70 |
Correct |
524 ms |
38912 KB |
Output is correct |