# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
378281 |
2021-03-16T11:30:59 Z |
Blerargh |
Race (IOI11_race) |
C++17 |
|
490 ms |
110696 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _ <<" "<<
#define cerr if(false)cerr
/*
Test case :
11 12
0 1 3
0 2 4
2 3 5
3 4 4
4 5 6
0 6 3
6 7 2
6 8 5
8 9 6
8 10 7
2
Test case :
4 3
0 1 1
1 2 2
1 3 4
2
*/
typedef pair<ll,ll> ii;
typedef tuple<ll,ll,ll,ll> tl; //actual dist, tree dist, offset, node
const ll MAXN = 2e5+5;
const ll INF = 1e18;
vector<ii> adjlist[MAXN];
bool visited[MAXN];
multiset<ii> s[MAXN];
ll ans=INF, stsize[MAXN], k;
void setmerging(ll u, ll dis, ll dep){
visited[u] = 1;
stsize[u] = 1;
ll maxsize=0, maxid=-1;
for (auto v : adjlist[u]){
if (visited[v.first]) continue;
setmerging(v.first, dis+v.second, dep+1);
stsize[u] += stsize[v.first];
if (stsize[v.first] > maxsize){
maxsize = stsize[v.first];
maxid = v.first;
}
}
s[u].emplace(dis, dep);
if (maxid != -1) s[u].swap(s[maxid]);
for (auto v : adjlist[u]){
ll node = v.first;
for (auto ss : s[node]){
ll actdist = ss.first;
ll treedist = ss.second;
auto it = s[u].lower_bound(make_pair(k-actdist+2ll*dis, 0ll));
if (it != s[u].end() && (*it).first == k - actdist + 2ll*dis){
ans = min(ans, treedist + (*it).second - 2ll*dep);
cerr << "Found:" _ "{" << ss.first << "," _ ss.second << "}, {" << (*it).first << "," _ (*it).second << "}\n";
}
}
for (auto ss : s[node]) s[u].emplace(ss);
}
}
int best_path(int N, int K, int H[][2], int L[]){
k = K;
for (int i=0; i<N-1; i++){
ll a = H[i][0], b = H[i][1], w = L[i];
adjlist[a].emplace_back(b, w);
adjlist[b].emplace_back(a, w);
}
setmerging(0, 0, 0);
if (ans == INF) return -1;
else return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
11 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
10 ms |
14480 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14572 KB |
Output is correct |
10 |
Correct |
11 ms |
14444 KB |
Output is correct |
11 |
Correct |
9 ms |
14444 KB |
Output is correct |
12 |
Correct |
11 ms |
14400 KB |
Output is correct |
13 |
Correct |
9 ms |
14444 KB |
Output is correct |
14 |
Correct |
11 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
11 ms |
14592 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
11 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
10 ms |
14480 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14572 KB |
Output is correct |
10 |
Correct |
11 ms |
14444 KB |
Output is correct |
11 |
Correct |
9 ms |
14444 KB |
Output is correct |
12 |
Correct |
11 ms |
14400 KB |
Output is correct |
13 |
Correct |
9 ms |
14444 KB |
Output is correct |
14 |
Correct |
11 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
11 ms |
14592 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14444 KB |
Output is correct |
19 |
Correct |
10 ms |
14444 KB |
Output is correct |
20 |
Correct |
9 ms |
14444 KB |
Output is correct |
21 |
Correct |
11 ms |
14700 KB |
Output is correct |
22 |
Correct |
11 ms |
14700 KB |
Output is correct |
23 |
Correct |
11 ms |
14700 KB |
Output is correct |
24 |
Correct |
11 ms |
14700 KB |
Output is correct |
25 |
Correct |
11 ms |
14700 KB |
Output is correct |
26 |
Correct |
11 ms |
14700 KB |
Output is correct |
27 |
Correct |
11 ms |
14700 KB |
Output is correct |
28 |
Correct |
11 ms |
14700 KB |
Output is correct |
29 |
Correct |
14 ms |
14700 KB |
Output is correct |
30 |
Correct |
12 ms |
14700 KB |
Output is correct |
31 |
Correct |
12 ms |
14828 KB |
Output is correct |
32 |
Correct |
11 ms |
14700 KB |
Output is correct |
33 |
Correct |
11 ms |
14700 KB |
Output is correct |
34 |
Correct |
11 ms |
14700 KB |
Output is correct |
35 |
Correct |
10 ms |
14700 KB |
Output is correct |
36 |
Correct |
10 ms |
14700 KB |
Output is correct |
37 |
Correct |
11 ms |
14700 KB |
Output is correct |
38 |
Correct |
11 ms |
14700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
11 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
10 ms |
14480 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14572 KB |
Output is correct |
10 |
Correct |
11 ms |
14444 KB |
Output is correct |
11 |
Correct |
9 ms |
14444 KB |
Output is correct |
12 |
Correct |
11 ms |
14400 KB |
Output is correct |
13 |
Correct |
9 ms |
14444 KB |
Output is correct |
14 |
Correct |
11 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
11 ms |
14592 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14444 KB |
Output is correct |
19 |
Correct |
254 ms |
60780 KB |
Output is correct |
20 |
Correct |
231 ms |
59756 KB |
Output is correct |
21 |
Correct |
259 ms |
60908 KB |
Output is correct |
22 |
Correct |
239 ms |
56044 KB |
Output is correct |
23 |
Correct |
272 ms |
73964 KB |
Output is correct |
24 |
Correct |
224 ms |
57964 KB |
Output is correct |
25 |
Correct |
174 ms |
42476 KB |
Output is correct |
26 |
Correct |
102 ms |
46060 KB |
Output is correct |
27 |
Correct |
334 ms |
69484 KB |
Output is correct |
28 |
Correct |
332 ms |
77944 KB |
Output is correct |
29 |
Correct |
325 ms |
77292 KB |
Output is correct |
30 |
Correct |
379 ms |
69540 KB |
Output is correct |
31 |
Correct |
339 ms |
69484 KB |
Output is correct |
32 |
Correct |
429 ms |
69612 KB |
Output is correct |
33 |
Correct |
396 ms |
89964 KB |
Output is correct |
34 |
Correct |
420 ms |
88428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
14444 KB |
Output is correct |
2 |
Correct |
11 ms |
14444 KB |
Output is correct |
3 |
Correct |
10 ms |
14444 KB |
Output is correct |
4 |
Correct |
10 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
10 ms |
14444 KB |
Output is correct |
7 |
Correct |
10 ms |
14480 KB |
Output is correct |
8 |
Correct |
10 ms |
14444 KB |
Output is correct |
9 |
Correct |
10 ms |
14572 KB |
Output is correct |
10 |
Correct |
11 ms |
14444 KB |
Output is correct |
11 |
Correct |
9 ms |
14444 KB |
Output is correct |
12 |
Correct |
11 ms |
14400 KB |
Output is correct |
13 |
Correct |
9 ms |
14444 KB |
Output is correct |
14 |
Correct |
11 ms |
14444 KB |
Output is correct |
15 |
Correct |
10 ms |
14444 KB |
Output is correct |
16 |
Correct |
11 ms |
14592 KB |
Output is correct |
17 |
Correct |
10 ms |
14444 KB |
Output is correct |
18 |
Correct |
10 ms |
14444 KB |
Output is correct |
19 |
Correct |
10 ms |
14444 KB |
Output is correct |
20 |
Correct |
9 ms |
14444 KB |
Output is correct |
21 |
Correct |
11 ms |
14700 KB |
Output is correct |
22 |
Correct |
11 ms |
14700 KB |
Output is correct |
23 |
Correct |
11 ms |
14700 KB |
Output is correct |
24 |
Correct |
11 ms |
14700 KB |
Output is correct |
25 |
Correct |
11 ms |
14700 KB |
Output is correct |
26 |
Correct |
11 ms |
14700 KB |
Output is correct |
27 |
Correct |
11 ms |
14700 KB |
Output is correct |
28 |
Correct |
11 ms |
14700 KB |
Output is correct |
29 |
Correct |
14 ms |
14700 KB |
Output is correct |
30 |
Correct |
12 ms |
14700 KB |
Output is correct |
31 |
Correct |
12 ms |
14828 KB |
Output is correct |
32 |
Correct |
11 ms |
14700 KB |
Output is correct |
33 |
Correct |
11 ms |
14700 KB |
Output is correct |
34 |
Correct |
11 ms |
14700 KB |
Output is correct |
35 |
Correct |
10 ms |
14700 KB |
Output is correct |
36 |
Correct |
10 ms |
14700 KB |
Output is correct |
37 |
Correct |
11 ms |
14700 KB |
Output is correct |
38 |
Correct |
11 ms |
14700 KB |
Output is correct |
39 |
Correct |
254 ms |
60780 KB |
Output is correct |
40 |
Correct |
231 ms |
59756 KB |
Output is correct |
41 |
Correct |
259 ms |
60908 KB |
Output is correct |
42 |
Correct |
239 ms |
56044 KB |
Output is correct |
43 |
Correct |
272 ms |
73964 KB |
Output is correct |
44 |
Correct |
224 ms |
57964 KB |
Output is correct |
45 |
Correct |
174 ms |
42476 KB |
Output is correct |
46 |
Correct |
102 ms |
46060 KB |
Output is correct |
47 |
Correct |
334 ms |
69484 KB |
Output is correct |
48 |
Correct |
332 ms |
77944 KB |
Output is correct |
49 |
Correct |
325 ms |
77292 KB |
Output is correct |
50 |
Correct |
379 ms |
69540 KB |
Output is correct |
51 |
Correct |
339 ms |
69484 KB |
Output is correct |
52 |
Correct |
429 ms |
69612 KB |
Output is correct |
53 |
Correct |
396 ms |
89964 KB |
Output is correct |
54 |
Correct |
420 ms |
88428 KB |
Output is correct |
55 |
Correct |
24 ms |
18028 KB |
Output is correct |
56 |
Correct |
25 ms |
18388 KB |
Output is correct |
57 |
Correct |
239 ms |
77548 KB |
Output is correct |
58 |
Correct |
113 ms |
34908 KB |
Output is correct |
59 |
Correct |
98 ms |
46072 KB |
Output is correct |
60 |
Correct |
320 ms |
77548 KB |
Output is correct |
61 |
Correct |
355 ms |
69612 KB |
Output is correct |
62 |
Correct |
326 ms |
69612 KB |
Output is correct |
63 |
Correct |
434 ms |
69484 KB |
Output is correct |
64 |
Correct |
490 ms |
110696 KB |
Output is correct |
65 |
Correct |
489 ms |
101868 KB |
Output is correct |
66 |
Correct |
350 ms |
75884 KB |
Output is correct |
67 |
Correct |
333 ms |
56532 KB |
Output is correct |
68 |
Correct |
443 ms |
68844 KB |
Output is correct |
69 |
Correct |
428 ms |
69100 KB |
Output is correct |
70 |
Correct |
420 ms |
66412 KB |
Output is correct |