# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
709942 |
2023-03-15T00:19:22 Z |
Ozy |
Race (IOI11_race) |
C++17 |
|
1332 ms |
55428 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli>
#define MAX 200000
#define des first
#define d second
vector<pll> hijos[MAX+2];
lli n,k,res,act,padre,mitad;
//centroid
lli tam[MAX+2],vis[MAX+2];
queue<lli> cola;
bool cond;
map<lli,lli> abso,rama;
void dfs(lli pos, lli p) {
tam[pos] = 1;
for(auto h : hijos[pos]) {
if (vis[h.des] == 1 || h.des == p) continue;
dfs(h.des,pos);
tam[pos] += tam[h.des];
}
}
void sub(lli pos, lli p,lli cam, lli sum) {
//checa contra abso
if (sum > k) return;
lli x,a = k-sum;
if (abso.find(a) != abso.end()) {
x = abso[a] + cam;
if (res == -1 || res > x) res = x;
}
//me meto a rama
if (rama.find(sum) != rama.end()) rama[sum] = min(rama[sum],cam);
else rama[sum] = cam;
//sigo procesando el subarbol
for(auto h : hijos[pos]) {
if (h.des == p || vis[h.des] == 1) continue;
sub(h.des,pos,cam+1,sum+h.d);
}
}
void solve(lli raiz) {
abso.clear();
abso[0] = 0;
for(auto h : hijos[raiz]) {
if (vis[h.des] == 1) continue;
rama.clear();
sub(h.des,raiz,1,h.d);
if (rama.size() > abso.size()) swap(abso,rama);
for (auto act : rama) {
if (abso.find(act.first) != abso.end()) abso[act.first] = min(abso[act.first], act.second);
else abso[act.first] = act.second;
}
}
}
int best_path(int N, int K, int H[][2], int L[])
{
n = N;
k = K;
res = -1;
rep(i,0,n-2) {
hijos[H[i][0]+1].push_back({H[i][1]+1, L[i]});
hijos[H[i][1]+1].push_back({H[i][0]+1, L[i]});
}
cola.push(1);
while(!cola.empty()){
act = cola.front();
cola.pop();
dfs(act,0); //obtengo el centroide
mitad = tam[act]/2;
padre = 0;
do{
cond = false;
for(auto h : hijos[act]) {
if (h.des == padre || vis[h.des] == 1 || tam[h.des] <= mitad) continue;
padre = act;
act = h.des;
cond = true;
break;
}
}while(cond);
solve(act);
vis[act] = 1;
for(auto h : hijos[act]) {
if (vis[h.des] == 1) continue;
cola.push(h.des);
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
5016 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4936 KB |
Output is correct |
6 |
Correct |
5 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 |
5012 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
5008 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5016 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 |
4944 KB |
Output is correct |
18 |
Correct |
3 ms |
5012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
5016 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4936 KB |
Output is correct |
6 |
Correct |
5 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 |
5012 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
5008 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5016 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 |
4944 KB |
Output is correct |
18 |
Correct |
3 ms |
5012 KB |
Output is correct |
19 |
Correct |
4 ms |
5012 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
5 ms |
5076 KB |
Output is correct |
22 |
Correct |
4 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
4 ms |
5076 KB |
Output is correct |
25 |
Correct |
5 ms |
5100 KB |
Output is correct |
26 |
Correct |
4 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
5 ms |
5076 KB |
Output is correct |
29 |
Correct |
4 ms |
5076 KB |
Output is correct |
30 |
Correct |
4 ms |
5152 KB |
Output is correct |
31 |
Correct |
4 ms |
5076 KB |
Output is correct |
32 |
Correct |
5 ms |
5204 KB |
Output is correct |
33 |
Correct |
5 ms |
5152 KB |
Output is correct |
34 |
Correct |
6 ms |
5076 KB |
Output is correct |
35 |
Correct |
5 ms |
5076 KB |
Output is correct |
36 |
Correct |
6 ms |
5084 KB |
Output is correct |
37 |
Correct |
6 ms |
5148 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 |
5016 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4936 KB |
Output is correct |
6 |
Correct |
5 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 |
5012 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
5008 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5016 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 |
4944 KB |
Output is correct |
18 |
Correct |
3 ms |
5012 KB |
Output is correct |
19 |
Correct |
278 ms |
14328 KB |
Output is correct |
20 |
Correct |
259 ms |
14328 KB |
Output is correct |
21 |
Correct |
276 ms |
14540 KB |
Output is correct |
22 |
Correct |
254 ms |
14564 KB |
Output is correct |
23 |
Correct |
125 ms |
14924 KB |
Output is correct |
24 |
Correct |
87 ms |
14488 KB |
Output is correct |
25 |
Correct |
149 ms |
18160 KB |
Output is correct |
26 |
Correct |
111 ms |
21812 KB |
Output is correct |
27 |
Correct |
253 ms |
24616 KB |
Output is correct |
28 |
Correct |
484 ms |
39160 KB |
Output is correct |
29 |
Correct |
443 ms |
37984 KB |
Output is correct |
30 |
Correct |
252 ms |
24524 KB |
Output is correct |
31 |
Correct |
256 ms |
24576 KB |
Output is correct |
32 |
Correct |
384 ms |
24756 KB |
Output is correct |
33 |
Correct |
450 ms |
23380 KB |
Output is correct |
34 |
Correct |
352 ms |
24200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
5016 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4936 KB |
Output is correct |
6 |
Correct |
5 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 |
5012 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
4 ms |
5008 KB |
Output is correct |
12 |
Correct |
3 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
5016 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 |
4944 KB |
Output is correct |
18 |
Correct |
3 ms |
5012 KB |
Output is correct |
19 |
Correct |
4 ms |
5012 KB |
Output is correct |
20 |
Correct |
4 ms |
4948 KB |
Output is correct |
21 |
Correct |
5 ms |
5076 KB |
Output is correct |
22 |
Correct |
4 ms |
5076 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
4 ms |
5076 KB |
Output is correct |
25 |
Correct |
5 ms |
5100 KB |
Output is correct |
26 |
Correct |
4 ms |
5076 KB |
Output is correct |
27 |
Correct |
3 ms |
5076 KB |
Output is correct |
28 |
Correct |
5 ms |
5076 KB |
Output is correct |
29 |
Correct |
4 ms |
5076 KB |
Output is correct |
30 |
Correct |
4 ms |
5152 KB |
Output is correct |
31 |
Correct |
4 ms |
5076 KB |
Output is correct |
32 |
Correct |
5 ms |
5204 KB |
Output is correct |
33 |
Correct |
5 ms |
5152 KB |
Output is correct |
34 |
Correct |
6 ms |
5076 KB |
Output is correct |
35 |
Correct |
5 ms |
5076 KB |
Output is correct |
36 |
Correct |
6 ms |
5084 KB |
Output is correct |
37 |
Correct |
6 ms |
5148 KB |
Output is correct |
38 |
Correct |
6 ms |
5076 KB |
Output is correct |
39 |
Correct |
278 ms |
14328 KB |
Output is correct |
40 |
Correct |
259 ms |
14328 KB |
Output is correct |
41 |
Correct |
276 ms |
14540 KB |
Output is correct |
42 |
Correct |
254 ms |
14564 KB |
Output is correct |
43 |
Correct |
125 ms |
14924 KB |
Output is correct |
44 |
Correct |
87 ms |
14488 KB |
Output is correct |
45 |
Correct |
149 ms |
18160 KB |
Output is correct |
46 |
Correct |
111 ms |
21812 KB |
Output is correct |
47 |
Correct |
253 ms |
24616 KB |
Output is correct |
48 |
Correct |
484 ms |
39160 KB |
Output is correct |
49 |
Correct |
443 ms |
37984 KB |
Output is correct |
50 |
Correct |
252 ms |
24524 KB |
Output is correct |
51 |
Correct |
256 ms |
24576 KB |
Output is correct |
52 |
Correct |
384 ms |
24756 KB |
Output is correct |
53 |
Correct |
450 ms |
23380 KB |
Output is correct |
54 |
Correct |
352 ms |
24200 KB |
Output is correct |
55 |
Correct |
23 ms |
6096 KB |
Output is correct |
56 |
Correct |
16 ms |
5864 KB |
Output is correct |
57 |
Correct |
150 ms |
14912 KB |
Output is correct |
58 |
Correct |
54 ms |
14388 KB |
Output is correct |
59 |
Correct |
364 ms |
29424 KB |
Output is correct |
60 |
Correct |
1239 ms |
55428 KB |
Output is correct |
61 |
Correct |
345 ms |
24804 KB |
Output is correct |
62 |
Correct |
366 ms |
24684 KB |
Output is correct |
63 |
Correct |
509 ms |
24684 KB |
Output is correct |
64 |
Correct |
1332 ms |
32948 KB |
Output is correct |
65 |
Correct |
372 ms |
25008 KB |
Output is correct |
66 |
Correct |
830 ms |
35480 KB |
Output is correct |
67 |
Correct |
151 ms |
24948 KB |
Output is correct |
68 |
Correct |
513 ms |
29028 KB |
Output is correct |
69 |
Correct |
514 ms |
29004 KB |
Output is correct |
70 |
Correct |
519 ms |
27908 KB |
Output is correct |