# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
331440 |
2020-11-28T13:40:39 Z |
2fat2code |
Race (IOI11_race) |
C++17 |
|
1705 ms |
52584 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
const int nmax = 200005;
int tot;
int sub[nmax], used[nmax], ans = 1e9;
vector <pair<int,int>> nod[nmax];
void calc(int s, int par = 0){
sub[s] = 1;
for(auto it : nod[s]){
if(used[it.fr] == 0 && it.fr != par){
calc(it.fr, s);
sub[s] += sub[it.fr];
}
}
}
int find_centroid(int s, int nec, int par = 0){
for(auto it : nod[s]){
if(used[it.fr] == 0 && it.fr != par && sub[it.fr] > nec){
return find_centroid(it.fr, nec, s);
}
}
return s;
}
void dfs(int s, map<int,int>&aux, int len, int nredge, int par = 0){
if(aux.count(len) == 0){
aux[len] = nredge;
}
else{
aux[len] = min(aux[len], nredge);
}
for(auto it : nod[s]){
if(it.fr != par && used[it.fr] == 0){
dfs(it.fr, aux, len + it.sc, nredge + 1, s);
}
}
}
void centroid(int s){
calc(s);
int centr = find_centroid(s, sub[s] / 2);
map<int, int> aux, fin;
fin[0] = 0;
used[centr] = 1;
for(auto it : nod[centr]){
if(used[it.fr] == 0){
dfs(it.fr, aux, it.sc, 1);
for(auto it1 : aux){
if(fin.count(tot - it1.fr) == 1){
ans = min(ans, it1.sc + fin[tot - it1.fr]);
}
}
for(auto it1 : aux){
if(fin.count(it1.fr) == 0){
fin[it1.fr] = it1.sc;
}
else{
fin[it1.fr] = min(fin[it1.fr], it1.sc);
}
}
aux.clear();
centroid(it.fr);
}
}
}
int best_path(int N, int K, int H[][2], int L[]){
tot = K;
for(int i=1;i<N;i++){
nod[H[i-1][0]].push_back({H[i-1][1], L[i-1]});
nod[H[i-1][1]].push_back({H[i-1][0], L[i-1]});
}
centroid(0);
if(ans == 1e9){
return -1;
}
else{
return ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5120 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
5 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5100 KB |
Output is correct |
16 |
Correct |
5 ms |
5100 KB |
Output is correct |
17 |
Correct |
4 ms |
5100 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5120 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
5 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5100 KB |
Output is correct |
16 |
Correct |
5 ms |
5100 KB |
Output is correct |
17 |
Correct |
4 ms |
5100 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
19 |
Correct |
4 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
5100 KB |
Output is correct |
21 |
Correct |
6 ms |
5100 KB |
Output is correct |
22 |
Correct |
6 ms |
5228 KB |
Output is correct |
23 |
Correct |
6 ms |
5248 KB |
Output is correct |
24 |
Correct |
6 ms |
5228 KB |
Output is correct |
25 |
Correct |
6 ms |
5228 KB |
Output is correct |
26 |
Correct |
6 ms |
5100 KB |
Output is correct |
27 |
Correct |
5 ms |
5100 KB |
Output is correct |
28 |
Correct |
8 ms |
5228 KB |
Output is correct |
29 |
Correct |
7 ms |
5100 KB |
Output is correct |
30 |
Correct |
6 ms |
5228 KB |
Output is correct |
31 |
Correct |
6 ms |
5228 KB |
Output is correct |
32 |
Correct |
6 ms |
5228 KB |
Output is correct |
33 |
Correct |
6 ms |
5228 KB |
Output is correct |
34 |
Correct |
6 ms |
5228 KB |
Output is correct |
35 |
Correct |
6 ms |
5228 KB |
Output is correct |
36 |
Correct |
6 ms |
5228 KB |
Output is correct |
37 |
Correct |
6 ms |
5228 KB |
Output is correct |
38 |
Correct |
6 ms |
5248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5120 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
5 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5100 KB |
Output is correct |
16 |
Correct |
5 ms |
5100 KB |
Output is correct |
17 |
Correct |
4 ms |
5100 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
19 |
Correct |
355 ms |
12140 KB |
Output is correct |
20 |
Correct |
333 ms |
12140 KB |
Output is correct |
21 |
Correct |
328 ms |
12160 KB |
Output is correct |
22 |
Correct |
306 ms |
12228 KB |
Output is correct |
23 |
Correct |
482 ms |
12804 KB |
Output is correct |
24 |
Correct |
215 ms |
12384 KB |
Output is correct |
25 |
Correct |
257 ms |
18412 KB |
Output is correct |
26 |
Correct |
121 ms |
19308 KB |
Output is correct |
27 |
Correct |
489 ms |
19692 KB |
Output is correct |
28 |
Correct |
1695 ms |
52584 KB |
Output is correct |
29 |
Correct |
1701 ms |
51480 KB |
Output is correct |
30 |
Correct |
470 ms |
19692 KB |
Output is correct |
31 |
Correct |
480 ms |
19692 KB |
Output is correct |
32 |
Correct |
574 ms |
19820 KB |
Output is correct |
33 |
Correct |
818 ms |
18796 KB |
Output is correct |
34 |
Correct |
1618 ms |
33152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
4 ms |
5100 KB |
Output is correct |
5 |
Correct |
4 ms |
5100 KB |
Output is correct |
6 |
Correct |
4 ms |
5100 KB |
Output is correct |
7 |
Correct |
4 ms |
5100 KB |
Output is correct |
8 |
Correct |
4 ms |
5120 KB |
Output is correct |
9 |
Correct |
4 ms |
5100 KB |
Output is correct |
10 |
Correct |
4 ms |
5100 KB |
Output is correct |
11 |
Correct |
4 ms |
5100 KB |
Output is correct |
12 |
Correct |
5 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
4 ms |
5100 KB |
Output is correct |
16 |
Correct |
5 ms |
5100 KB |
Output is correct |
17 |
Correct |
4 ms |
5100 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
19 |
Correct |
4 ms |
4992 KB |
Output is correct |
20 |
Correct |
4 ms |
5100 KB |
Output is correct |
21 |
Correct |
6 ms |
5100 KB |
Output is correct |
22 |
Correct |
6 ms |
5228 KB |
Output is correct |
23 |
Correct |
6 ms |
5248 KB |
Output is correct |
24 |
Correct |
6 ms |
5228 KB |
Output is correct |
25 |
Correct |
6 ms |
5228 KB |
Output is correct |
26 |
Correct |
6 ms |
5100 KB |
Output is correct |
27 |
Correct |
5 ms |
5100 KB |
Output is correct |
28 |
Correct |
8 ms |
5228 KB |
Output is correct |
29 |
Correct |
7 ms |
5100 KB |
Output is correct |
30 |
Correct |
6 ms |
5228 KB |
Output is correct |
31 |
Correct |
6 ms |
5228 KB |
Output is correct |
32 |
Correct |
6 ms |
5228 KB |
Output is correct |
33 |
Correct |
6 ms |
5228 KB |
Output is correct |
34 |
Correct |
6 ms |
5228 KB |
Output is correct |
35 |
Correct |
6 ms |
5228 KB |
Output is correct |
36 |
Correct |
6 ms |
5228 KB |
Output is correct |
37 |
Correct |
6 ms |
5228 KB |
Output is correct |
38 |
Correct |
6 ms |
5248 KB |
Output is correct |
39 |
Correct |
355 ms |
12140 KB |
Output is correct |
40 |
Correct |
333 ms |
12140 KB |
Output is correct |
41 |
Correct |
328 ms |
12160 KB |
Output is correct |
42 |
Correct |
306 ms |
12228 KB |
Output is correct |
43 |
Correct |
482 ms |
12804 KB |
Output is correct |
44 |
Correct |
215 ms |
12384 KB |
Output is correct |
45 |
Correct |
257 ms |
18412 KB |
Output is correct |
46 |
Correct |
121 ms |
19308 KB |
Output is correct |
47 |
Correct |
489 ms |
19692 KB |
Output is correct |
48 |
Correct |
1695 ms |
52584 KB |
Output is correct |
49 |
Correct |
1701 ms |
51480 KB |
Output is correct |
50 |
Correct |
470 ms |
19692 KB |
Output is correct |
51 |
Correct |
480 ms |
19692 KB |
Output is correct |
52 |
Correct |
574 ms |
19820 KB |
Output is correct |
53 |
Correct |
818 ms |
18796 KB |
Output is correct |
54 |
Correct |
1618 ms |
33152 KB |
Output is correct |
55 |
Correct |
35 ms |
6124 KB |
Output is correct |
56 |
Correct |
20 ms |
5740 KB |
Output is correct |
57 |
Correct |
199 ms |
12396 KB |
Output is correct |
58 |
Correct |
63 ms |
12000 KB |
Output is correct |
59 |
Correct |
551 ms |
26604 KB |
Output is correct |
60 |
Correct |
1700 ms |
50248 KB |
Output is correct |
61 |
Correct |
607 ms |
21356 KB |
Output is correct |
62 |
Correct |
454 ms |
19820 KB |
Output is correct |
63 |
Correct |
569 ms |
20076 KB |
Output is correct |
64 |
Correct |
1661 ms |
27928 KB |
Output is correct |
65 |
Correct |
1430 ms |
30940 KB |
Output is correct |
66 |
Correct |
1705 ms |
49900 KB |
Output is correct |
67 |
Correct |
195 ms |
20316 KB |
Output is correct |
68 |
Correct |
833 ms |
28504 KB |
Output is correct |
69 |
Correct |
878 ms |
28652 KB |
Output is correct |
70 |
Correct |
772 ms |
27372 KB |
Output is correct |