# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
742240 |
2023-05-16T00:06:38 Z |
beaboss |
Race (IOI11_race) |
C++14 |
|
495 ms |
111092 KB |
#include <bits/stdc++.h>
using namespace std;
#define s second
#define f first
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;
typedef vector<ll> vi;
#define FOR(i, a, b) for (ll i = (a); i<b; i++)
const ll MN = 3e5 + 10;
vpii adj[MN];
ll d[MN]; // from root in highways
ll d2[MN]; // from root in distance
ll k;
map<ll, ll> small[MN];
void dfs(ll cur = 0, ll dist = 0, ll dist2 = 0, ll p = -1) {
// cout << cur << endl;
d[cur]=dist;
d2[cur]=dist2;
small[cur][dist2]=dist;
for (auto val: adj[cur]) {
if (val.f != p) {
dfs(val.f, dist + 1ll, dist2 + val.s, cur);
}
}
}
ll ans = 1e9;
void solve(ll cur, ll p=-1) {
ll target = k + 2*d2[cur];
for (auto val: adj[cur]) {
if (val.f != p) {
solve(val.f, cur);
if (small[val.f].size() > small[cur].size()) swap(small[val.f], small[cur]);
for (pii nx: small[val.f]) {
if (small[cur].find(target - nx.f) != small[cur].end()) {
ans = min(ans, small[cur][target - nx.f] + nx.s - 2*d[cur]);
}
}
for (pii nx: small[val.f]) {
if (small[cur].find(nx.f) == small[cur].end()) small[cur].insert(nx);
else small[cur][nx.f]=min(small[cur][nx.f], nx.s);
}
}
}
}
int best_path(int N, int K, int H[][2], int L[])
{
k = K;
FOR(i, 0, N-1) {
adj[H[i][0]].pb({H[i][1], L[i]});
adj[H[i][1]].pb({H[i][0], L[i]});
}
dfs();
solve(0);
if (ans == 1e9) ans = -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
21460 KB |
Output is correct |
2 |
Correct |
13 ms |
21512 KB |
Output is correct |
3 |
Correct |
12 ms |
21444 KB |
Output is correct |
4 |
Correct |
14 ms |
21460 KB |
Output is correct |
5 |
Correct |
13 ms |
21452 KB |
Output is correct |
6 |
Correct |
13 ms |
21460 KB |
Output is correct |
7 |
Correct |
13 ms |
21420 KB |
Output is correct |
8 |
Correct |
12 ms |
21460 KB |
Output is correct |
9 |
Correct |
14 ms |
21508 KB |
Output is correct |
10 |
Correct |
11 ms |
21496 KB |
Output is correct |
11 |
Correct |
10 ms |
21388 KB |
Output is correct |
12 |
Correct |
11 ms |
21424 KB |
Output is correct |
13 |
Correct |
12 ms |
21460 KB |
Output is correct |
14 |
Correct |
11 ms |
21484 KB |
Output is correct |
15 |
Correct |
11 ms |
21508 KB |
Output is correct |
16 |
Correct |
11 ms |
21508 KB |
Output is correct |
17 |
Correct |
11 ms |
21460 KB |
Output is correct |
18 |
Correct |
13 ms |
21460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
21460 KB |
Output is correct |
2 |
Correct |
13 ms |
21512 KB |
Output is correct |
3 |
Correct |
12 ms |
21444 KB |
Output is correct |
4 |
Correct |
14 ms |
21460 KB |
Output is correct |
5 |
Correct |
13 ms |
21452 KB |
Output is correct |
6 |
Correct |
13 ms |
21460 KB |
Output is correct |
7 |
Correct |
13 ms |
21420 KB |
Output is correct |
8 |
Correct |
12 ms |
21460 KB |
Output is correct |
9 |
Correct |
14 ms |
21508 KB |
Output is correct |
10 |
Correct |
11 ms |
21496 KB |
Output is correct |
11 |
Correct |
10 ms |
21388 KB |
Output is correct |
12 |
Correct |
11 ms |
21424 KB |
Output is correct |
13 |
Correct |
12 ms |
21460 KB |
Output is correct |
14 |
Correct |
11 ms |
21484 KB |
Output is correct |
15 |
Correct |
11 ms |
21508 KB |
Output is correct |
16 |
Correct |
11 ms |
21508 KB |
Output is correct |
17 |
Correct |
11 ms |
21460 KB |
Output is correct |
18 |
Correct |
13 ms |
21460 KB |
Output is correct |
19 |
Correct |
11 ms |
21472 KB |
Output is correct |
20 |
Correct |
11 ms |
21472 KB |
Output is correct |
21 |
Correct |
12 ms |
21716 KB |
Output is correct |
22 |
Correct |
11 ms |
21816 KB |
Output is correct |
23 |
Correct |
13 ms |
21712 KB |
Output is correct |
24 |
Correct |
12 ms |
21784 KB |
Output is correct |
25 |
Correct |
12 ms |
21688 KB |
Output is correct |
26 |
Correct |
12 ms |
21688 KB |
Output is correct |
27 |
Correct |
12 ms |
21564 KB |
Output is correct |
28 |
Correct |
13 ms |
21784 KB |
Output is correct |
29 |
Correct |
12 ms |
21716 KB |
Output is correct |
30 |
Correct |
13 ms |
21716 KB |
Output is correct |
31 |
Correct |
12 ms |
21680 KB |
Output is correct |
32 |
Correct |
11 ms |
21716 KB |
Output is correct |
33 |
Correct |
11 ms |
21820 KB |
Output is correct |
34 |
Correct |
11 ms |
21748 KB |
Output is correct |
35 |
Correct |
12 ms |
21720 KB |
Output is correct |
36 |
Correct |
12 ms |
21652 KB |
Output is correct |
37 |
Correct |
11 ms |
21716 KB |
Output is correct |
38 |
Correct |
12 ms |
21704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
21460 KB |
Output is correct |
2 |
Correct |
13 ms |
21512 KB |
Output is correct |
3 |
Correct |
12 ms |
21444 KB |
Output is correct |
4 |
Correct |
14 ms |
21460 KB |
Output is correct |
5 |
Correct |
13 ms |
21452 KB |
Output is correct |
6 |
Correct |
13 ms |
21460 KB |
Output is correct |
7 |
Correct |
13 ms |
21420 KB |
Output is correct |
8 |
Correct |
12 ms |
21460 KB |
Output is correct |
9 |
Correct |
14 ms |
21508 KB |
Output is correct |
10 |
Correct |
11 ms |
21496 KB |
Output is correct |
11 |
Correct |
10 ms |
21388 KB |
Output is correct |
12 |
Correct |
11 ms |
21424 KB |
Output is correct |
13 |
Correct |
12 ms |
21460 KB |
Output is correct |
14 |
Correct |
11 ms |
21484 KB |
Output is correct |
15 |
Correct |
11 ms |
21508 KB |
Output is correct |
16 |
Correct |
11 ms |
21508 KB |
Output is correct |
17 |
Correct |
11 ms |
21460 KB |
Output is correct |
18 |
Correct |
13 ms |
21460 KB |
Output is correct |
19 |
Correct |
154 ms |
44876 KB |
Output is correct |
20 |
Correct |
141 ms |
44824 KB |
Output is correct |
21 |
Correct |
137 ms |
44632 KB |
Output is correct |
22 |
Correct |
144 ms |
44144 KB |
Output is correct |
23 |
Correct |
176 ms |
56972 KB |
Output is correct |
24 |
Correct |
139 ms |
47060 KB |
Output is correct |
25 |
Correct |
125 ms |
45684 KB |
Output is correct |
26 |
Correct |
66 ms |
53836 KB |
Output is correct |
27 |
Correct |
240 ms |
56688 KB |
Output is correct |
28 |
Correct |
359 ms |
98752 KB |
Output is correct |
29 |
Correct |
346 ms |
96972 KB |
Output is correct |
30 |
Correct |
238 ms |
56740 KB |
Output is correct |
31 |
Correct |
244 ms |
56648 KB |
Output is correct |
32 |
Correct |
335 ms |
56708 KB |
Output is correct |
33 |
Correct |
283 ms |
61604 KB |
Output is correct |
34 |
Correct |
416 ms |
93612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
21460 KB |
Output is correct |
2 |
Correct |
13 ms |
21512 KB |
Output is correct |
3 |
Correct |
12 ms |
21444 KB |
Output is correct |
4 |
Correct |
14 ms |
21460 KB |
Output is correct |
5 |
Correct |
13 ms |
21452 KB |
Output is correct |
6 |
Correct |
13 ms |
21460 KB |
Output is correct |
7 |
Correct |
13 ms |
21420 KB |
Output is correct |
8 |
Correct |
12 ms |
21460 KB |
Output is correct |
9 |
Correct |
14 ms |
21508 KB |
Output is correct |
10 |
Correct |
11 ms |
21496 KB |
Output is correct |
11 |
Correct |
10 ms |
21388 KB |
Output is correct |
12 |
Correct |
11 ms |
21424 KB |
Output is correct |
13 |
Correct |
12 ms |
21460 KB |
Output is correct |
14 |
Correct |
11 ms |
21484 KB |
Output is correct |
15 |
Correct |
11 ms |
21508 KB |
Output is correct |
16 |
Correct |
11 ms |
21508 KB |
Output is correct |
17 |
Correct |
11 ms |
21460 KB |
Output is correct |
18 |
Correct |
13 ms |
21460 KB |
Output is correct |
19 |
Correct |
11 ms |
21472 KB |
Output is correct |
20 |
Correct |
11 ms |
21472 KB |
Output is correct |
21 |
Correct |
12 ms |
21716 KB |
Output is correct |
22 |
Correct |
11 ms |
21816 KB |
Output is correct |
23 |
Correct |
13 ms |
21712 KB |
Output is correct |
24 |
Correct |
12 ms |
21784 KB |
Output is correct |
25 |
Correct |
12 ms |
21688 KB |
Output is correct |
26 |
Correct |
12 ms |
21688 KB |
Output is correct |
27 |
Correct |
12 ms |
21564 KB |
Output is correct |
28 |
Correct |
13 ms |
21784 KB |
Output is correct |
29 |
Correct |
12 ms |
21716 KB |
Output is correct |
30 |
Correct |
13 ms |
21716 KB |
Output is correct |
31 |
Correct |
12 ms |
21680 KB |
Output is correct |
32 |
Correct |
11 ms |
21716 KB |
Output is correct |
33 |
Correct |
11 ms |
21820 KB |
Output is correct |
34 |
Correct |
11 ms |
21748 KB |
Output is correct |
35 |
Correct |
12 ms |
21720 KB |
Output is correct |
36 |
Correct |
12 ms |
21652 KB |
Output is correct |
37 |
Correct |
11 ms |
21716 KB |
Output is correct |
38 |
Correct |
12 ms |
21704 KB |
Output is correct |
39 |
Correct |
154 ms |
44876 KB |
Output is correct |
40 |
Correct |
141 ms |
44824 KB |
Output is correct |
41 |
Correct |
137 ms |
44632 KB |
Output is correct |
42 |
Correct |
144 ms |
44144 KB |
Output is correct |
43 |
Correct |
176 ms |
56972 KB |
Output is correct |
44 |
Correct |
139 ms |
47060 KB |
Output is correct |
45 |
Correct |
125 ms |
45684 KB |
Output is correct |
46 |
Correct |
66 ms |
53836 KB |
Output is correct |
47 |
Correct |
240 ms |
56688 KB |
Output is correct |
48 |
Correct |
359 ms |
98752 KB |
Output is correct |
49 |
Correct |
346 ms |
96972 KB |
Output is correct |
50 |
Correct |
238 ms |
56740 KB |
Output is correct |
51 |
Correct |
244 ms |
56648 KB |
Output is correct |
52 |
Correct |
335 ms |
56708 KB |
Output is correct |
53 |
Correct |
283 ms |
61604 KB |
Output is correct |
54 |
Correct |
416 ms |
93612 KB |
Output is correct |
55 |
Correct |
23 ms |
24788 KB |
Output is correct |
56 |
Correct |
18 ms |
23508 KB |
Output is correct |
57 |
Correct |
82 ms |
42296 KB |
Output is correct |
58 |
Correct |
55 ms |
35088 KB |
Output is correct |
59 |
Correct |
128 ms |
60180 KB |
Output is correct |
60 |
Correct |
322 ms |
97632 KB |
Output is correct |
61 |
Correct |
276 ms |
60044 KB |
Output is correct |
62 |
Correct |
230 ms |
56724 KB |
Output is correct |
63 |
Correct |
314 ms |
56732 KB |
Output is correct |
64 |
Correct |
476 ms |
111092 KB |
Output is correct |
65 |
Correct |
495 ms |
108912 KB |
Output is correct |
66 |
Correct |
357 ms |
92716 KB |
Output is correct |
67 |
Correct |
201 ms |
49112 KB |
Output is correct |
68 |
Correct |
395 ms |
72596 KB |
Output is correct |
69 |
Correct |
417 ms |
77184 KB |
Output is correct |
70 |
Correct |
354 ms |
70344 KB |
Output is correct |