# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
429472 |
2021-06-16T01:05:03 Z |
hibye1217 |
Race (IOI11_race) |
C++17 |
|
676 ms |
38040 KB |
#ifndef NOTSUBMIT
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
#endif // NOTSUBMIT
typedef long long ll;
typedef pair<ll, ll> pl2;
typedef pair<int, int> pi2;
#define fr first
#define sc second
vector<pl2> adj[200020];
bool chk[200020];
int sz[200020];
int siz(int now, int par){
//cout << " SIZ " << now << ' ' << par << endl;
sz[now] = 1;
for (pl2 p : adj[now]){
//cout << " P " << p.fr << ' ' << p.sc << endl;
int nxt = p.fr;
if (nxt == par || chk[nxt]){ continue; }
//cout << " ?? " << nxt << ' ' << now << endl;
sz[now] += siz(nxt, now);
}
//cout << " SIZE " << now << ' ' << sz[now] << endl;
return sz[now];
}
int cen(int now){
siz(now, -1);
int ptr = now, tar = sz[now] / 2;
int par = -1;
while (1){
bool flg = 1;
for (pl2 p : adj[ptr]){
int nxt = p.fr;
if (par == nxt || chk[nxt] || sz[nxt] <= tar){ continue; }
flg = 0; par = ptr; ptr = nxt; break;
}
if (flg){ return ptr; }
}
}
int k;
vector<pi2> v;
int dp[1000020];
queue<int> q;
void dpf(int now, int par, int dep, ll dis){
if (dis > k){ return; }
v.push_back({dep, dis});
for (pl2 p : adj[now]){
int nxt = p.fr; ll dst = p.sc;
if (par == nxt || chk[nxt]){ continue; }
dpf(nxt, now, dep+1, dis+dst);
}
}
int ans = 1e9;
void f(int now){
int r = cen(now);
//cout << "CEN " << now << ' ' << r << endl;
for (pl2 p : adj[r]){
int nxt = p.fr; ll dis = p.sc;
if (chk[nxt]){ continue; }
dpf(nxt, r, 1, dis);
for (pi2 pp : v){
int dep = pp.fr, dst = pp.sc;
q.push(dst);
//cout << "ANS " << dep << ' ' << dst << ' ';
if (dp[k-dst] != -1){ ans = min(ans, dp[k-dst] + dep); }
//cout << ans << endl;
}
for (pi2 pp : v){
int dep = pp.fr, dst = pp.sc;
//cout << "DP " << dst << ' ' << dp[dst] << ' ' << dep << endl;
if (dp[dst] == -1){ dp[dst] = dep; }
else{ dp[dst] = min(dp[dst], dep); }
}
v.clear();
}
while (!q.empty()){ dp[q.front()] = -1; q.pop(); }
chk[r] = 1;
for (pl2 p : adj[r]){
int nxt = p.fr;
if (chk[nxt]){ continue; }
f(nxt);
}
}
int best_path(int N, int K, int H[][2], int L[]){
for (int i = 0; i < N-1; i++){
adj[ H[i][0] ].push_back({ H[i][1], L[i] });
adj[ H[i][1] ].push_back({ H[i][0], L[i] });
}
k = K; memset(dp, -1, sizeof(dp)); dp[0] = 0;
f(0);
if (ans == 1e9){ return -1; }
else{ return ans; }
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8908 KB |
Output is correct |
2 |
Correct |
6 ms |
8908 KB |
Output is correct |
3 |
Correct |
6 ms |
8908 KB |
Output is correct |
4 |
Correct |
6 ms |
8868 KB |
Output is correct |
5 |
Correct |
6 ms |
8908 KB |
Output is correct |
6 |
Correct |
6 ms |
8908 KB |
Output is correct |
7 |
Correct |
6 ms |
8908 KB |
Output is correct |
8 |
Correct |
6 ms |
8908 KB |
Output is correct |
9 |
Correct |
6 ms |
8908 KB |
Output is correct |
10 |
Correct |
6 ms |
8848 KB |
Output is correct |
11 |
Correct |
6 ms |
8908 KB |
Output is correct |
12 |
Correct |
6 ms |
8908 KB |
Output is correct |
13 |
Correct |
7 ms |
8908 KB |
Output is correct |
14 |
Correct |
6 ms |
8908 KB |
Output is correct |
15 |
Correct |
6 ms |
8908 KB |
Output is correct |
16 |
Correct |
6 ms |
8908 KB |
Output is correct |
17 |
Correct |
6 ms |
8880 KB |
Output is correct |
18 |
Correct |
6 ms |
8908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8908 KB |
Output is correct |
2 |
Correct |
6 ms |
8908 KB |
Output is correct |
3 |
Correct |
6 ms |
8908 KB |
Output is correct |
4 |
Correct |
6 ms |
8868 KB |
Output is correct |
5 |
Correct |
6 ms |
8908 KB |
Output is correct |
6 |
Correct |
6 ms |
8908 KB |
Output is correct |
7 |
Correct |
6 ms |
8908 KB |
Output is correct |
8 |
Correct |
6 ms |
8908 KB |
Output is correct |
9 |
Correct |
6 ms |
8908 KB |
Output is correct |
10 |
Correct |
6 ms |
8848 KB |
Output is correct |
11 |
Correct |
6 ms |
8908 KB |
Output is correct |
12 |
Correct |
6 ms |
8908 KB |
Output is correct |
13 |
Correct |
7 ms |
8908 KB |
Output is correct |
14 |
Correct |
6 ms |
8908 KB |
Output is correct |
15 |
Correct |
6 ms |
8908 KB |
Output is correct |
16 |
Correct |
6 ms |
8908 KB |
Output is correct |
17 |
Correct |
6 ms |
8880 KB |
Output is correct |
18 |
Correct |
6 ms |
8908 KB |
Output is correct |
19 |
Correct |
6 ms |
8908 KB |
Output is correct |
20 |
Correct |
6 ms |
8904 KB |
Output is correct |
21 |
Correct |
7 ms |
8908 KB |
Output is correct |
22 |
Correct |
7 ms |
8908 KB |
Output is correct |
23 |
Correct |
6 ms |
8908 KB |
Output is correct |
24 |
Correct |
7 ms |
8908 KB |
Output is correct |
25 |
Correct |
7 ms |
8908 KB |
Output is correct |
26 |
Correct |
7 ms |
8908 KB |
Output is correct |
27 |
Correct |
7 ms |
8968 KB |
Output is correct |
28 |
Correct |
7 ms |
8908 KB |
Output is correct |
29 |
Correct |
7 ms |
8908 KB |
Output is correct |
30 |
Correct |
6 ms |
8908 KB |
Output is correct |
31 |
Correct |
6 ms |
8908 KB |
Output is correct |
32 |
Correct |
7 ms |
8908 KB |
Output is correct |
33 |
Correct |
7 ms |
8920 KB |
Output is correct |
34 |
Correct |
7 ms |
8912 KB |
Output is correct |
35 |
Correct |
8 ms |
8908 KB |
Output is correct |
36 |
Correct |
7 ms |
8908 KB |
Output is correct |
37 |
Correct |
7 ms |
8908 KB |
Output is correct |
38 |
Correct |
7 ms |
8908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8908 KB |
Output is correct |
2 |
Correct |
6 ms |
8908 KB |
Output is correct |
3 |
Correct |
6 ms |
8908 KB |
Output is correct |
4 |
Correct |
6 ms |
8868 KB |
Output is correct |
5 |
Correct |
6 ms |
8908 KB |
Output is correct |
6 |
Correct |
6 ms |
8908 KB |
Output is correct |
7 |
Correct |
6 ms |
8908 KB |
Output is correct |
8 |
Correct |
6 ms |
8908 KB |
Output is correct |
9 |
Correct |
6 ms |
8908 KB |
Output is correct |
10 |
Correct |
6 ms |
8848 KB |
Output is correct |
11 |
Correct |
6 ms |
8908 KB |
Output is correct |
12 |
Correct |
6 ms |
8908 KB |
Output is correct |
13 |
Correct |
7 ms |
8908 KB |
Output is correct |
14 |
Correct |
6 ms |
8908 KB |
Output is correct |
15 |
Correct |
6 ms |
8908 KB |
Output is correct |
16 |
Correct |
6 ms |
8908 KB |
Output is correct |
17 |
Correct |
6 ms |
8880 KB |
Output is correct |
18 |
Correct |
6 ms |
8908 KB |
Output is correct |
19 |
Correct |
161 ms |
15788 KB |
Output is correct |
20 |
Correct |
179 ms |
15908 KB |
Output is correct |
21 |
Correct |
175 ms |
16084 KB |
Output is correct |
22 |
Correct |
158 ms |
16328 KB |
Output is correct |
23 |
Correct |
102 ms |
16048 KB |
Output is correct |
24 |
Correct |
72 ms |
15216 KB |
Output is correct |
25 |
Correct |
146 ms |
18628 KB |
Output is correct |
26 |
Correct |
115 ms |
22336 KB |
Output is correct |
27 |
Correct |
220 ms |
22976 KB |
Output is correct |
28 |
Correct |
381 ms |
34116 KB |
Output is correct |
29 |
Correct |
327 ms |
33076 KB |
Output is correct |
30 |
Correct |
252 ms |
22996 KB |
Output is correct |
31 |
Correct |
227 ms |
23012 KB |
Output is correct |
32 |
Correct |
279 ms |
23012 KB |
Output is correct |
33 |
Correct |
287 ms |
21756 KB |
Output is correct |
34 |
Correct |
245 ms |
21704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8908 KB |
Output is correct |
2 |
Correct |
6 ms |
8908 KB |
Output is correct |
3 |
Correct |
6 ms |
8908 KB |
Output is correct |
4 |
Correct |
6 ms |
8868 KB |
Output is correct |
5 |
Correct |
6 ms |
8908 KB |
Output is correct |
6 |
Correct |
6 ms |
8908 KB |
Output is correct |
7 |
Correct |
6 ms |
8908 KB |
Output is correct |
8 |
Correct |
6 ms |
8908 KB |
Output is correct |
9 |
Correct |
6 ms |
8908 KB |
Output is correct |
10 |
Correct |
6 ms |
8848 KB |
Output is correct |
11 |
Correct |
6 ms |
8908 KB |
Output is correct |
12 |
Correct |
6 ms |
8908 KB |
Output is correct |
13 |
Correct |
7 ms |
8908 KB |
Output is correct |
14 |
Correct |
6 ms |
8908 KB |
Output is correct |
15 |
Correct |
6 ms |
8908 KB |
Output is correct |
16 |
Correct |
6 ms |
8908 KB |
Output is correct |
17 |
Correct |
6 ms |
8880 KB |
Output is correct |
18 |
Correct |
6 ms |
8908 KB |
Output is correct |
19 |
Correct |
6 ms |
8908 KB |
Output is correct |
20 |
Correct |
6 ms |
8904 KB |
Output is correct |
21 |
Correct |
7 ms |
8908 KB |
Output is correct |
22 |
Correct |
7 ms |
8908 KB |
Output is correct |
23 |
Correct |
6 ms |
8908 KB |
Output is correct |
24 |
Correct |
7 ms |
8908 KB |
Output is correct |
25 |
Correct |
7 ms |
8908 KB |
Output is correct |
26 |
Correct |
7 ms |
8908 KB |
Output is correct |
27 |
Correct |
7 ms |
8968 KB |
Output is correct |
28 |
Correct |
7 ms |
8908 KB |
Output is correct |
29 |
Correct |
7 ms |
8908 KB |
Output is correct |
30 |
Correct |
6 ms |
8908 KB |
Output is correct |
31 |
Correct |
6 ms |
8908 KB |
Output is correct |
32 |
Correct |
7 ms |
8908 KB |
Output is correct |
33 |
Correct |
7 ms |
8920 KB |
Output is correct |
34 |
Correct |
7 ms |
8912 KB |
Output is correct |
35 |
Correct |
8 ms |
8908 KB |
Output is correct |
36 |
Correct |
7 ms |
8908 KB |
Output is correct |
37 |
Correct |
7 ms |
8908 KB |
Output is correct |
38 |
Correct |
7 ms |
8908 KB |
Output is correct |
39 |
Correct |
161 ms |
15788 KB |
Output is correct |
40 |
Correct |
179 ms |
15908 KB |
Output is correct |
41 |
Correct |
175 ms |
16084 KB |
Output is correct |
42 |
Correct |
158 ms |
16328 KB |
Output is correct |
43 |
Correct |
102 ms |
16048 KB |
Output is correct |
44 |
Correct |
72 ms |
15216 KB |
Output is correct |
45 |
Correct |
146 ms |
18628 KB |
Output is correct |
46 |
Correct |
115 ms |
22336 KB |
Output is correct |
47 |
Correct |
220 ms |
22976 KB |
Output is correct |
48 |
Correct |
381 ms |
34116 KB |
Output is correct |
49 |
Correct |
327 ms |
33076 KB |
Output is correct |
50 |
Correct |
252 ms |
22996 KB |
Output is correct |
51 |
Correct |
227 ms |
23012 KB |
Output is correct |
52 |
Correct |
279 ms |
23012 KB |
Output is correct |
53 |
Correct |
287 ms |
21756 KB |
Output is correct |
54 |
Correct |
245 ms |
21704 KB |
Output is correct |
55 |
Correct |
20 ms |
9548 KB |
Output is correct |
56 |
Correct |
16 ms |
9676 KB |
Output is correct |
57 |
Correct |
102 ms |
16700 KB |
Output is correct |
58 |
Correct |
47 ms |
15604 KB |
Output is correct |
59 |
Correct |
117 ms |
23704 KB |
Output is correct |
60 |
Correct |
598 ms |
38040 KB |
Output is correct |
61 |
Correct |
236 ms |
26200 KB |
Output is correct |
62 |
Correct |
276 ms |
26700 KB |
Output is correct |
63 |
Correct |
337 ms |
26796 KB |
Output is correct |
64 |
Correct |
676 ms |
27440 KB |
Output is correct |
65 |
Correct |
326 ms |
26356 KB |
Output is correct |
66 |
Correct |
478 ms |
34420 KB |
Output is correct |
67 |
Correct |
184 ms |
25768 KB |
Output is correct |
68 |
Correct |
330 ms |
26364 KB |
Output is correct |
69 |
Correct |
336 ms |
26528 KB |
Output is correct |
70 |
Correct |
343 ms |
25604 KB |
Output is correct |