# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
904804 |
2024-01-12T08:36:24 Z |
ALTAKEXE |
Race (IOI11_race) |
C++14 |
|
346 ms |
76652 KB |
#include "race.h"
#include "bits/stdc++.h"
#define MAXN 200009
#define INF 1000000007
#define mp(x, y) make_pair(x, y)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define ppb() pop_back()
#define tr(ii, c) for (__typeof((c).begin()) ii = (c).begin(); ii != (c).end(); ii++)
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
template <class T>
bool umin(T &a, T b)
{
if (a > b)
{
a = b;
return 1;
}
return 0;
}
template <class T>
bool umax(T &a, T b)
{
if (a < b)
{
a = b;
return 1;
}
return 0;
}
int n, k, ans = INF;
ll dis[MAXN];
vector<PII> adj[MAXN];
set<pair<ll, int>> s[MAXN];
void dfs(int nd, int pr, int lvl)
{
tr(it, adj[nd])
{
int to = it->ff;
if (to != pr)
{
dis[to] = dis[nd] + it->ss;
dfs(to, nd, lvl + 1);
if ((int)s[to].size() > (int)s[nd].size())
swap(s[to], s[nd]);
__typeof((s[nd]).begin()) itt;
tr(it, s[to]) if (dis[nd] * 2 + k >= it->ff)
{
itt = s[nd].lower_bound(mp(dis[nd] * 2 + k - it->ff, -1));
if (itt != s[nd].end() and itt->ff + it->ff == k + dis[nd] * 2)
umin(ans, it->ss + itt->ss - 2 * lvl);
}
tr(it, s[to]) s[nd].insert(*it);
s[to].clear();
}
}
s[nd].insert(mp(dis[nd], lvl));
__typeof((s[nd]).begin()) itt = s[nd].lower_bound(mp(k + dis[nd], -1));
if (itt != s[nd].end() and itt->ff - dis[nd] == k)
umin(ans, itt->ss - lvl);
}
int best_path(int N, int K, int h[][2], int l[])
{
n = N, k = K;
for (int i = 0; i < n - 1; i++)
{
int u = h[i][0], v = h[i][1];
adj[u].pb(mp(v, l[i]));
adj[v].pb(mp(u, l[i]));
}
dfs(1, -1, 0);
if (ans == INF)
ans = -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
18776 KB |
Output is correct |
2 |
Correct |
5 ms |
18780 KB |
Output is correct |
3 |
Correct |
7 ms |
18884 KB |
Output is correct |
4 |
Correct |
5 ms |
18780 KB |
Output is correct |
5 |
Correct |
5 ms |
18780 KB |
Output is correct |
6 |
Correct |
5 ms |
18780 KB |
Output is correct |
7 |
Correct |
5 ms |
18888 KB |
Output is correct |
8 |
Correct |
5 ms |
18780 KB |
Output is correct |
9 |
Correct |
5 ms |
18780 KB |
Output is correct |
10 |
Correct |
7 ms |
19036 KB |
Output is correct |
11 |
Correct |
5 ms |
18780 KB |
Output is correct |
12 |
Correct |
5 ms |
18776 KB |
Output is correct |
13 |
Correct |
6 ms |
18780 KB |
Output is correct |
14 |
Correct |
5 ms |
18868 KB |
Output is correct |
15 |
Correct |
5 ms |
18780 KB |
Output is correct |
16 |
Correct |
6 ms |
18776 KB |
Output is correct |
17 |
Correct |
5 ms |
18780 KB |
Output is correct |
18 |
Correct |
5 ms |
18776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
18776 KB |
Output is correct |
2 |
Correct |
5 ms |
18780 KB |
Output is correct |
3 |
Correct |
7 ms |
18884 KB |
Output is correct |
4 |
Correct |
5 ms |
18780 KB |
Output is correct |
5 |
Correct |
5 ms |
18780 KB |
Output is correct |
6 |
Correct |
5 ms |
18780 KB |
Output is correct |
7 |
Correct |
5 ms |
18888 KB |
Output is correct |
8 |
Correct |
5 ms |
18780 KB |
Output is correct |
9 |
Correct |
5 ms |
18780 KB |
Output is correct |
10 |
Correct |
7 ms |
19036 KB |
Output is correct |
11 |
Correct |
5 ms |
18780 KB |
Output is correct |
12 |
Correct |
5 ms |
18776 KB |
Output is correct |
13 |
Correct |
6 ms |
18780 KB |
Output is correct |
14 |
Correct |
5 ms |
18868 KB |
Output is correct |
15 |
Correct |
5 ms |
18780 KB |
Output is correct |
16 |
Correct |
6 ms |
18776 KB |
Output is correct |
17 |
Correct |
5 ms |
18780 KB |
Output is correct |
18 |
Correct |
5 ms |
18776 KB |
Output is correct |
19 |
Correct |
5 ms |
18800 KB |
Output is correct |
20 |
Correct |
5 ms |
18916 KB |
Output is correct |
21 |
Correct |
6 ms |
18780 KB |
Output is correct |
22 |
Correct |
6 ms |
18780 KB |
Output is correct |
23 |
Correct |
6 ms |
18780 KB |
Output is correct |
24 |
Correct |
6 ms |
18780 KB |
Output is correct |
25 |
Correct |
7 ms |
18896 KB |
Output is correct |
26 |
Correct |
6 ms |
18780 KB |
Output is correct |
27 |
Correct |
5 ms |
18880 KB |
Output is correct |
28 |
Correct |
6 ms |
18780 KB |
Output is correct |
29 |
Correct |
6 ms |
19016 KB |
Output is correct |
30 |
Correct |
5 ms |
18780 KB |
Output is correct |
31 |
Correct |
6 ms |
18916 KB |
Output is correct |
32 |
Correct |
5 ms |
19036 KB |
Output is correct |
33 |
Correct |
6 ms |
18780 KB |
Output is correct |
34 |
Correct |
5 ms |
19036 KB |
Output is correct |
35 |
Correct |
6 ms |
19036 KB |
Output is correct |
36 |
Correct |
6 ms |
19036 KB |
Output is correct |
37 |
Correct |
5 ms |
19036 KB |
Output is correct |
38 |
Correct |
5 ms |
19036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
18776 KB |
Output is correct |
2 |
Correct |
5 ms |
18780 KB |
Output is correct |
3 |
Correct |
7 ms |
18884 KB |
Output is correct |
4 |
Correct |
5 ms |
18780 KB |
Output is correct |
5 |
Correct |
5 ms |
18780 KB |
Output is correct |
6 |
Correct |
5 ms |
18780 KB |
Output is correct |
7 |
Correct |
5 ms |
18888 KB |
Output is correct |
8 |
Correct |
5 ms |
18780 KB |
Output is correct |
9 |
Correct |
5 ms |
18780 KB |
Output is correct |
10 |
Correct |
7 ms |
19036 KB |
Output is correct |
11 |
Correct |
5 ms |
18780 KB |
Output is correct |
12 |
Correct |
5 ms |
18776 KB |
Output is correct |
13 |
Correct |
6 ms |
18780 KB |
Output is correct |
14 |
Correct |
5 ms |
18868 KB |
Output is correct |
15 |
Correct |
5 ms |
18780 KB |
Output is correct |
16 |
Correct |
6 ms |
18776 KB |
Output is correct |
17 |
Correct |
5 ms |
18780 KB |
Output is correct |
18 |
Correct |
5 ms |
18776 KB |
Output is correct |
19 |
Correct |
100 ms |
25172 KB |
Output is correct |
20 |
Correct |
100 ms |
26456 KB |
Output is correct |
21 |
Correct |
88 ms |
26492 KB |
Output is correct |
22 |
Correct |
100 ms |
26708 KB |
Output is correct |
23 |
Correct |
113 ms |
27260 KB |
Output is correct |
24 |
Correct |
91 ms |
26468 KB |
Output is correct |
25 |
Correct |
101 ms |
47956 KB |
Output is correct |
26 |
Correct |
72 ms |
48980 KB |
Output is correct |
27 |
Correct |
160 ms |
35668 KB |
Output is correct |
28 |
Correct |
258 ms |
76652 KB |
Output is correct |
29 |
Correct |
246 ms |
69264 KB |
Output is correct |
30 |
Correct |
150 ms |
35764 KB |
Output is correct |
31 |
Correct |
169 ms |
35720 KB |
Output is correct |
32 |
Correct |
217 ms |
35672 KB |
Output is correct |
33 |
Correct |
176 ms |
31828 KB |
Output is correct |
34 |
Correct |
325 ms |
45504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
18776 KB |
Output is correct |
2 |
Correct |
5 ms |
18780 KB |
Output is correct |
3 |
Correct |
7 ms |
18884 KB |
Output is correct |
4 |
Correct |
5 ms |
18780 KB |
Output is correct |
5 |
Correct |
5 ms |
18780 KB |
Output is correct |
6 |
Correct |
5 ms |
18780 KB |
Output is correct |
7 |
Correct |
5 ms |
18888 KB |
Output is correct |
8 |
Correct |
5 ms |
18780 KB |
Output is correct |
9 |
Correct |
5 ms |
18780 KB |
Output is correct |
10 |
Correct |
7 ms |
19036 KB |
Output is correct |
11 |
Correct |
5 ms |
18780 KB |
Output is correct |
12 |
Correct |
5 ms |
18776 KB |
Output is correct |
13 |
Correct |
6 ms |
18780 KB |
Output is correct |
14 |
Correct |
5 ms |
18868 KB |
Output is correct |
15 |
Correct |
5 ms |
18780 KB |
Output is correct |
16 |
Correct |
6 ms |
18776 KB |
Output is correct |
17 |
Correct |
5 ms |
18780 KB |
Output is correct |
18 |
Correct |
5 ms |
18776 KB |
Output is correct |
19 |
Correct |
5 ms |
18800 KB |
Output is correct |
20 |
Correct |
5 ms |
18916 KB |
Output is correct |
21 |
Correct |
6 ms |
18780 KB |
Output is correct |
22 |
Correct |
6 ms |
18780 KB |
Output is correct |
23 |
Correct |
6 ms |
18780 KB |
Output is correct |
24 |
Correct |
6 ms |
18780 KB |
Output is correct |
25 |
Correct |
7 ms |
18896 KB |
Output is correct |
26 |
Correct |
6 ms |
18780 KB |
Output is correct |
27 |
Correct |
5 ms |
18880 KB |
Output is correct |
28 |
Correct |
6 ms |
18780 KB |
Output is correct |
29 |
Correct |
6 ms |
19016 KB |
Output is correct |
30 |
Correct |
5 ms |
18780 KB |
Output is correct |
31 |
Correct |
6 ms |
18916 KB |
Output is correct |
32 |
Correct |
5 ms |
19036 KB |
Output is correct |
33 |
Correct |
6 ms |
18780 KB |
Output is correct |
34 |
Correct |
5 ms |
19036 KB |
Output is correct |
35 |
Correct |
6 ms |
19036 KB |
Output is correct |
36 |
Correct |
6 ms |
19036 KB |
Output is correct |
37 |
Correct |
5 ms |
19036 KB |
Output is correct |
38 |
Correct |
5 ms |
19036 KB |
Output is correct |
39 |
Correct |
100 ms |
25172 KB |
Output is correct |
40 |
Correct |
100 ms |
26456 KB |
Output is correct |
41 |
Correct |
88 ms |
26492 KB |
Output is correct |
42 |
Correct |
100 ms |
26708 KB |
Output is correct |
43 |
Correct |
113 ms |
27260 KB |
Output is correct |
44 |
Correct |
91 ms |
26468 KB |
Output is correct |
45 |
Correct |
101 ms |
47956 KB |
Output is correct |
46 |
Correct |
72 ms |
48980 KB |
Output is correct |
47 |
Correct |
160 ms |
35668 KB |
Output is correct |
48 |
Correct |
258 ms |
76652 KB |
Output is correct |
49 |
Correct |
246 ms |
69264 KB |
Output is correct |
50 |
Correct |
150 ms |
35764 KB |
Output is correct |
51 |
Correct |
169 ms |
35720 KB |
Output is correct |
52 |
Correct |
217 ms |
35672 KB |
Output is correct |
53 |
Correct |
176 ms |
31828 KB |
Output is correct |
54 |
Correct |
325 ms |
45504 KB |
Output is correct |
55 |
Correct |
15 ms |
20060 KB |
Output is correct |
56 |
Correct |
14 ms |
19484 KB |
Output is correct |
57 |
Correct |
54 ms |
26452 KB |
Output is correct |
58 |
Correct |
38 ms |
26056 KB |
Output is correct |
59 |
Correct |
76 ms |
49000 KB |
Output is correct |
60 |
Correct |
230 ms |
67532 KB |
Output is correct |
61 |
Correct |
203 ms |
40164 KB |
Output is correct |
62 |
Correct |
179 ms |
35796 KB |
Output is correct |
63 |
Correct |
197 ms |
35924 KB |
Output is correct |
64 |
Correct |
346 ms |
45688 KB |
Output is correct |
65 |
Correct |
341 ms |
46196 KB |
Output is correct |
66 |
Correct |
238 ms |
74792 KB |
Output is correct |
67 |
Correct |
152 ms |
33488 KB |
Output is correct |
68 |
Correct |
282 ms |
45520 KB |
Output is correct |
69 |
Correct |
314 ms |
50532 KB |
Output is correct |
70 |
Correct |
289 ms |
44524 KB |
Output is correct |