# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
580869 |
2022-06-22T03:37:57 Z |
benson1029 |
Race (IOI11_race) |
C++14 |
|
1039 ms |
49404 KB |
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
vector< pair<int,int> > edg[200005];
int k;
bool solved[200005];
int compsize[200005];
int mxdeg, centroid;
vector< pair<long long, int> > v;
set< pair<long long, int> > v2;
int ans = 1e9;
void findcentroid(int x, int p) {
compsize[x] = 1;
for(auto i:edg[x]) {
if(!solved[i.first] && i.first!=p) {
findcentroid(i.first, x);
compsize[x] += compsize[i.first];
}
}
}
void findcentroid2(int x, int p, int totsize) {
for(auto i:edg[x]) {
if(!solved[i.first] && i.first!=p) {
findcentroid2(i.first, x, totsize);
}
}
bool ok = true;
for(auto i:edg[x]) {
if(!solved[i.first] && i.first!=p) {
if(compsize[i.first] > totsize/2) ok = false;
}
}
if(totsize - compsize[x] > totsize/2) ok = false;
if(ok) centroid = x;
}
void solve(int x);
void findandsolve(int x) {
mxdeg = -1;
centroid = -1;
findcentroid(x, -1);
findcentroid2(x, -1, compsize[x]);
solve(centroid);
}
void dfs(int x, int p, long long len, int cnt) {
v.push_back({len, cnt});
for(auto i:edg[x]) {
if(solved[i.first]) continue;
if(i.first != p) {
dfs(i.first, x, len+i.second, cnt+1);
}
}
}
void solve(int x) {
v.clear(); v2.clear();
v2.insert({0, 0});
solved[x] = true;
for(auto i:edg[x]) {
if(solved[i.first]) continue;
v.clear();
dfs(i.first, -1, i.second, 1);
sort(v.begin(), v.end());
for(auto i:v) {
auto tmp = v2.lower_bound(make_pair(k-i.first, 0));
if(tmp!=v2.end() && (*tmp).first == k-i.first) {
ans = min(ans, (*tmp).second + i.second);
}
}
for(auto i:v) {
v2.insert(i);
}
}
for(auto i:edg[x]) {
if(solved[i.first]) continue;
findandsolve(i.first);
}
}
int best_path(int N, int K, int H[][2], int L[])
{
k = K;
for(int i=0; i<N-1; i++) {
edg[H[i][0]].push_back({H[i][1], L[i]});
edg[H[i][1]].push_back({H[i][0], L[i]});
}
compsize[0] = N;
findandsolve(0);
if(ans==1e9) return -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
5032 KB |
Output is correct |
6 |
Correct |
4 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 |
5036 KB |
Output is correct |
10 |
Correct |
5 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 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 |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
5032 KB |
Output is correct |
6 |
Correct |
4 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 |
5036 KB |
Output is correct |
10 |
Correct |
5 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 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 |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
6 ms |
5084 KB |
Output is correct |
22 |
Correct |
6 ms |
5076 KB |
Output is correct |
23 |
Correct |
4 ms |
5044 KB |
Output is correct |
24 |
Correct |
5 ms |
5160 KB |
Output is correct |
25 |
Correct |
4 ms |
5076 KB |
Output is correct |
26 |
Correct |
4 ms |
5076 KB |
Output is correct |
27 |
Correct |
4 ms |
5024 KB |
Output is correct |
28 |
Correct |
4 ms |
5076 KB |
Output is correct |
29 |
Correct |
9 ms |
5044 KB |
Output is correct |
30 |
Correct |
4 ms |
5076 KB |
Output is correct |
31 |
Correct |
5 ms |
5156 KB |
Output is correct |
32 |
Correct |
4 ms |
5076 KB |
Output is correct |
33 |
Correct |
5 ms |
5076 KB |
Output is correct |
34 |
Correct |
5 ms |
5152 KB |
Output is correct |
35 |
Correct |
5 ms |
5076 KB |
Output is correct |
36 |
Correct |
5 ms |
5076 KB |
Output is correct |
37 |
Correct |
4 ms |
5076 KB |
Output is correct |
38 |
Correct |
6 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
5032 KB |
Output is correct |
6 |
Correct |
4 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 |
5036 KB |
Output is correct |
10 |
Correct |
5 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 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 |
4948 KB |
Output is correct |
19 |
Correct |
327 ms |
11324 KB |
Output is correct |
20 |
Correct |
278 ms |
11400 KB |
Output is correct |
21 |
Correct |
274 ms |
11520 KB |
Output is correct |
22 |
Correct |
235 ms |
11572 KB |
Output is correct |
23 |
Correct |
390 ms |
11708 KB |
Output is correct |
24 |
Correct |
139 ms |
11156 KB |
Output is correct |
25 |
Correct |
426 ms |
21824 KB |
Output is correct |
26 |
Correct |
311 ms |
26092 KB |
Output is correct |
27 |
Correct |
366 ms |
19364 KB |
Output is correct |
28 |
Correct |
1022 ms |
47456 KB |
Output is correct |
29 |
Correct |
973 ms |
46028 KB |
Output is correct |
30 |
Correct |
342 ms |
19276 KB |
Output is correct |
31 |
Correct |
334 ms |
19312 KB |
Output is correct |
32 |
Correct |
432 ms |
19320 KB |
Output is correct |
33 |
Correct |
648 ms |
16892 KB |
Output is correct |
34 |
Correct |
764 ms |
28564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
4 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
4 ms |
5032 KB |
Output is correct |
6 |
Correct |
4 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 |
5036 KB |
Output is correct |
10 |
Correct |
5 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 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 |
4948 KB |
Output is correct |
19 |
Correct |
4 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
6 ms |
5084 KB |
Output is correct |
22 |
Correct |
6 ms |
5076 KB |
Output is correct |
23 |
Correct |
4 ms |
5044 KB |
Output is correct |
24 |
Correct |
5 ms |
5160 KB |
Output is correct |
25 |
Correct |
4 ms |
5076 KB |
Output is correct |
26 |
Correct |
4 ms |
5076 KB |
Output is correct |
27 |
Correct |
4 ms |
5024 KB |
Output is correct |
28 |
Correct |
4 ms |
5076 KB |
Output is correct |
29 |
Correct |
9 ms |
5044 KB |
Output is correct |
30 |
Correct |
4 ms |
5076 KB |
Output is correct |
31 |
Correct |
5 ms |
5156 KB |
Output is correct |
32 |
Correct |
4 ms |
5076 KB |
Output is correct |
33 |
Correct |
5 ms |
5076 KB |
Output is correct |
34 |
Correct |
5 ms |
5152 KB |
Output is correct |
35 |
Correct |
5 ms |
5076 KB |
Output is correct |
36 |
Correct |
5 ms |
5076 KB |
Output is correct |
37 |
Correct |
4 ms |
5076 KB |
Output is correct |
38 |
Correct |
6 ms |
5076 KB |
Output is correct |
39 |
Correct |
327 ms |
11324 KB |
Output is correct |
40 |
Correct |
278 ms |
11400 KB |
Output is correct |
41 |
Correct |
274 ms |
11520 KB |
Output is correct |
42 |
Correct |
235 ms |
11572 KB |
Output is correct |
43 |
Correct |
390 ms |
11708 KB |
Output is correct |
44 |
Correct |
139 ms |
11156 KB |
Output is correct |
45 |
Correct |
426 ms |
21824 KB |
Output is correct |
46 |
Correct |
311 ms |
26092 KB |
Output is correct |
47 |
Correct |
366 ms |
19364 KB |
Output is correct |
48 |
Correct |
1022 ms |
47456 KB |
Output is correct |
49 |
Correct |
973 ms |
46028 KB |
Output is correct |
50 |
Correct |
342 ms |
19276 KB |
Output is correct |
51 |
Correct |
334 ms |
19312 KB |
Output is correct |
52 |
Correct |
432 ms |
19320 KB |
Output is correct |
53 |
Correct |
648 ms |
16892 KB |
Output is correct |
54 |
Correct |
764 ms |
28564 KB |
Output is correct |
55 |
Correct |
23 ms |
6276 KB |
Output is correct |
56 |
Correct |
22 ms |
5772 KB |
Output is correct |
57 |
Correct |
211 ms |
12952 KB |
Output is correct |
58 |
Correct |
48 ms |
11584 KB |
Output is correct |
59 |
Correct |
329 ms |
27568 KB |
Output is correct |
60 |
Correct |
1018 ms |
49404 KB |
Output is correct |
61 |
Correct |
410 ms |
26244 KB |
Output is correct |
62 |
Correct |
397 ms |
22256 KB |
Output is correct |
63 |
Correct |
435 ms |
22184 KB |
Output is correct |
64 |
Correct |
1039 ms |
31920 KB |
Output is correct |
65 |
Correct |
869 ms |
33528 KB |
Output is correct |
66 |
Correct |
937 ms |
46092 KB |
Output is correct |
67 |
Correct |
150 ms |
19584 KB |
Output is correct |
68 |
Correct |
533 ms |
33424 KB |
Output is correct |
69 |
Correct |
537 ms |
33616 KB |
Output is correct |
70 |
Correct |
456 ms |
32008 KB |
Output is correct |