# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
109750 |
2019-05-07T21:49:13 Z |
m3r8 |
Race (IOI11_race) |
C++14 |
|
831 ms |
44240 KB |
#include <stdio.h>
#include <utility>
#include <string.h>
#include <vector>
#include "race.h"
#define ll long long
#define ii std::pair<int,int>
#define il std::pair<int,std::pair<int,std::pair<int,long long>>>
#define MAXN 200100
#define MAXK 1000000
std::vector<il> adj[MAXN];
int cnt;
int child[MAXN];
int posNxt[MAXN];
ii isDist[MAXK];
ll dist[MAXN];
int nKant[MAXN];
int szSub[MAXN];
ll k;
ll mn;
int trr;
void dfsSub(int v, int p){
szSub[v] = 0;
for(auto &edg: adj[v]){
int u = edg.first;
if(u != p && edg.second.first){
dfsSub(u,v);
szSub[v] += 1;
szSub[v] += szSub[u];
};
};
};
int findCent(int root, int par){
dfsSub(root, par);
int sz = szSub[root] + 1;
int akt = root;
int prev = par;
int mx = 0;
int nxt = -1;
while(true){
nxt = akt;
mx = sz - szSub[akt] - 1;
for(auto& edg:adj[akt]){
if(edg.first != prev && edg.second.first){
if(mx < szSub[edg.first]+1){
mx = szSub[edg.first]+1;
nxt = edg.first;
};
};
};
if(mx <= (sz/2)){
return akt;
}
else{
prev = akt;
akt = nxt;
};
};
};
void dfsST(int v, int par, ll cst, int num){
ll d = cst + dist[par];
dist[v] = d;
int knt = nKant[par] +1;
nKant[v] = knt;
child[cnt++] = v;
ll srch = k-d;
if(srch >= 0 && isDist[srch].first == num){
if(mn == -1 || mn > isDist[srch].second + knt){
mn = isDist[srch].second + knt;
};
};
for(auto &edg:adj[v]){
if(edg.first != par && edg.second.first){
dfsST(edg.first,v,edg.second.second.second,num);
};
};
};
void goFromCen(int cen){
trr++;
dist[cen] = 0;
nKant[cen] = 0;
for(auto &edg: adj[cen]){
if(edg.second.first){
edg.second.first = 0;
adj[edg.first][edg.second.second.first].second.first = 0;
cnt = 0;
dfsST(edg.first,cen,edg.second.second.second,trr);
for(int i = 0;i<cnt;i++){
if(dist[child[i]] > k)continue;
if(dist[child[i]] == k){
if(mn == -1 || nKant[child[i]] < mn){
mn = nKant[child[i]];
};
};
if(isDist[dist[child[i]]].first != trr){
isDist[dist[child[i]]].first = trr;
isDist[dist[child[i]]].second = nKant[child[i]];
}else if(isDist[dist[child[i]]].second > nKant[child[i]]){
isDist[dist[child[i]]].second = nKant[child[i]];
};
};
edg.second.first = 1;
};
};
for(auto &edg:adj[cen]){
if(edg.second.first){
edg.second.first = 0;
int nxtC = findCent(edg.first,cen);
goFromCen(nxtC);
};
};
};
int n;
int best_path(int n1,int k1,int H[][2],int L[]){
int a,b;
n = n1;
k=k1;
ll cst;
for(int i = 0;i<n-1;i++){
a = H[i][0];
b = H[i][1];
cst = L[i];
int sa = adj[a].size();
int sb = adj[b].size();
adj[a].push_back(il(0,std::pair<int,std::pair<int,long long>>(0,std::pair<int,long long>(0,0))));
adj[a][sa].first = b;
adj[a][sa].second.first = 1;
adj[a][sa].second.second.first = sb;
adj[a][sa].second.second.second = cst;
adj[b].push_back(il(0,std::pair<int,std::pair<int,long long>>(0,std::pair<int,long long>(0,0))));
adj[b][sb].first = a;
adj[b][sb].second.first = 1;
adj[b][sb].second.second.first = sa;
adj[b][sb].second.second.second = cst;
};
mn = -1;
cnt = 0;
trr = 1;
int c1 = findCent(0,-1);
goFromCen(c1);
return mn;
};
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
4992 KB |
Output is correct |
3 |
Correct |
6 ms |
5120 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
4988 KB |
Output is correct |
6 |
Correct |
6 ms |
5120 KB |
Output is correct |
7 |
Correct |
5 ms |
5120 KB |
Output is correct |
8 |
Correct |
6 ms |
4992 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
8 ms |
5120 KB |
Output is correct |
11 |
Correct |
7 ms |
5120 KB |
Output is correct |
12 |
Correct |
6 ms |
4992 KB |
Output is correct |
13 |
Correct |
6 ms |
4992 KB |
Output is correct |
14 |
Correct |
5 ms |
4992 KB |
Output is correct |
15 |
Correct |
7 ms |
5072 KB |
Output is correct |
16 |
Correct |
6 ms |
5120 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
4992 KB |
Output is correct |
3 |
Correct |
6 ms |
5120 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
4988 KB |
Output is correct |
6 |
Correct |
6 ms |
5120 KB |
Output is correct |
7 |
Correct |
5 ms |
5120 KB |
Output is correct |
8 |
Correct |
6 ms |
4992 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
8 ms |
5120 KB |
Output is correct |
11 |
Correct |
7 ms |
5120 KB |
Output is correct |
12 |
Correct |
6 ms |
4992 KB |
Output is correct |
13 |
Correct |
6 ms |
4992 KB |
Output is correct |
14 |
Correct |
5 ms |
4992 KB |
Output is correct |
15 |
Correct |
7 ms |
5072 KB |
Output is correct |
16 |
Correct |
6 ms |
5120 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
19 |
Correct |
5 ms |
4992 KB |
Output is correct |
20 |
Correct |
6 ms |
5120 KB |
Output is correct |
21 |
Correct |
7 ms |
5120 KB |
Output is correct |
22 |
Correct |
10 ms |
8576 KB |
Output is correct |
23 |
Correct |
11 ms |
8064 KB |
Output is correct |
24 |
Correct |
10 ms |
9216 KB |
Output is correct |
25 |
Correct |
11 ms |
8320 KB |
Output is correct |
26 |
Correct |
9 ms |
7424 KB |
Output is correct |
27 |
Correct |
7 ms |
5120 KB |
Output is correct |
28 |
Correct |
10 ms |
6784 KB |
Output is correct |
29 |
Correct |
9 ms |
7552 KB |
Output is correct |
30 |
Correct |
11 ms |
7808 KB |
Output is correct |
31 |
Correct |
11 ms |
8448 KB |
Output is correct |
32 |
Correct |
12 ms |
8576 KB |
Output is correct |
33 |
Correct |
12 ms |
9856 KB |
Output is correct |
34 |
Correct |
11 ms |
9088 KB |
Output is correct |
35 |
Correct |
12 ms |
10112 KB |
Output is correct |
36 |
Correct |
15 ms |
10492 KB |
Output is correct |
37 |
Correct |
10 ms |
8320 KB |
Output is correct |
38 |
Correct |
10 ms |
7296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
4992 KB |
Output is correct |
3 |
Correct |
6 ms |
5120 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
4988 KB |
Output is correct |
6 |
Correct |
6 ms |
5120 KB |
Output is correct |
7 |
Correct |
5 ms |
5120 KB |
Output is correct |
8 |
Correct |
6 ms |
4992 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
8 ms |
5120 KB |
Output is correct |
11 |
Correct |
7 ms |
5120 KB |
Output is correct |
12 |
Correct |
6 ms |
4992 KB |
Output is correct |
13 |
Correct |
6 ms |
4992 KB |
Output is correct |
14 |
Correct |
5 ms |
4992 KB |
Output is correct |
15 |
Correct |
7 ms |
5072 KB |
Output is correct |
16 |
Correct |
6 ms |
5120 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
19 |
Correct |
276 ms |
16832 KB |
Output is correct |
20 |
Correct |
268 ms |
16860 KB |
Output is correct |
21 |
Correct |
252 ms |
16860 KB |
Output is correct |
22 |
Correct |
188 ms |
16888 KB |
Output is correct |
23 |
Correct |
214 ms |
17528 KB |
Output is correct |
24 |
Correct |
134 ms |
15840 KB |
Output is correct |
25 |
Correct |
272 ms |
19300 KB |
Output is correct |
26 |
Correct |
116 ms |
22392 KB |
Output is correct |
27 |
Correct |
262 ms |
28628 KB |
Output is correct |
28 |
Correct |
641 ms |
39664 KB |
Output is correct |
29 |
Correct |
664 ms |
38868 KB |
Output is correct |
30 |
Correct |
285 ms |
28664 KB |
Output is correct |
31 |
Correct |
262 ms |
28792 KB |
Output is correct |
32 |
Correct |
426 ms |
28792 KB |
Output is correct |
33 |
Correct |
524 ms |
27388 KB |
Output is correct |
34 |
Correct |
520 ms |
27132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
4992 KB |
Output is correct |
3 |
Correct |
6 ms |
5120 KB |
Output is correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
6 ms |
4988 KB |
Output is correct |
6 |
Correct |
6 ms |
5120 KB |
Output is correct |
7 |
Correct |
5 ms |
5120 KB |
Output is correct |
8 |
Correct |
6 ms |
4992 KB |
Output is correct |
9 |
Correct |
6 ms |
5120 KB |
Output is correct |
10 |
Correct |
8 ms |
5120 KB |
Output is correct |
11 |
Correct |
7 ms |
5120 KB |
Output is correct |
12 |
Correct |
6 ms |
4992 KB |
Output is correct |
13 |
Correct |
6 ms |
4992 KB |
Output is correct |
14 |
Correct |
5 ms |
4992 KB |
Output is correct |
15 |
Correct |
7 ms |
5072 KB |
Output is correct |
16 |
Correct |
6 ms |
5120 KB |
Output is correct |
17 |
Correct |
4 ms |
5120 KB |
Output is correct |
18 |
Correct |
6 ms |
5120 KB |
Output is correct |
19 |
Correct |
5 ms |
4992 KB |
Output is correct |
20 |
Correct |
6 ms |
5120 KB |
Output is correct |
21 |
Correct |
7 ms |
5120 KB |
Output is correct |
22 |
Correct |
10 ms |
8576 KB |
Output is correct |
23 |
Correct |
11 ms |
8064 KB |
Output is correct |
24 |
Correct |
10 ms |
9216 KB |
Output is correct |
25 |
Correct |
11 ms |
8320 KB |
Output is correct |
26 |
Correct |
9 ms |
7424 KB |
Output is correct |
27 |
Correct |
7 ms |
5120 KB |
Output is correct |
28 |
Correct |
10 ms |
6784 KB |
Output is correct |
29 |
Correct |
9 ms |
7552 KB |
Output is correct |
30 |
Correct |
11 ms |
7808 KB |
Output is correct |
31 |
Correct |
11 ms |
8448 KB |
Output is correct |
32 |
Correct |
12 ms |
8576 KB |
Output is correct |
33 |
Correct |
12 ms |
9856 KB |
Output is correct |
34 |
Correct |
11 ms |
9088 KB |
Output is correct |
35 |
Correct |
12 ms |
10112 KB |
Output is correct |
36 |
Correct |
15 ms |
10492 KB |
Output is correct |
37 |
Correct |
10 ms |
8320 KB |
Output is correct |
38 |
Correct |
10 ms |
7296 KB |
Output is correct |
39 |
Correct |
276 ms |
16832 KB |
Output is correct |
40 |
Correct |
268 ms |
16860 KB |
Output is correct |
41 |
Correct |
252 ms |
16860 KB |
Output is correct |
42 |
Correct |
188 ms |
16888 KB |
Output is correct |
43 |
Correct |
214 ms |
17528 KB |
Output is correct |
44 |
Correct |
134 ms |
15840 KB |
Output is correct |
45 |
Correct |
272 ms |
19300 KB |
Output is correct |
46 |
Correct |
116 ms |
22392 KB |
Output is correct |
47 |
Correct |
262 ms |
28628 KB |
Output is correct |
48 |
Correct |
641 ms |
39664 KB |
Output is correct |
49 |
Correct |
664 ms |
38868 KB |
Output is correct |
50 |
Correct |
285 ms |
28664 KB |
Output is correct |
51 |
Correct |
262 ms |
28792 KB |
Output is correct |
52 |
Correct |
426 ms |
28792 KB |
Output is correct |
53 |
Correct |
524 ms |
27388 KB |
Output is correct |
54 |
Correct |
520 ms |
27132 KB |
Output is correct |
55 |
Correct |
16 ms |
6400 KB |
Output is correct |
56 |
Correct |
14 ms |
6272 KB |
Output is correct |
57 |
Correct |
79 ms |
17656 KB |
Output is correct |
58 |
Correct |
52 ms |
15844 KB |
Output is correct |
59 |
Correct |
116 ms |
23192 KB |
Output is correct |
60 |
Correct |
763 ms |
43668 KB |
Output is correct |
61 |
Correct |
312 ms |
28536 KB |
Output is correct |
62 |
Correct |
285 ms |
28408 KB |
Output is correct |
63 |
Correct |
394 ms |
28380 KB |
Output is correct |
64 |
Correct |
708 ms |
30840 KB |
Output is correct |
65 |
Correct |
544 ms |
28920 KB |
Output is correct |
66 |
Correct |
831 ms |
44240 KB |
Output is correct |
67 |
Correct |
226 ms |
26488 KB |
Output is correct |
68 |
Correct |
403 ms |
32848 KB |
Output is correct |
69 |
Correct |
460 ms |
33144 KB |
Output is correct |
70 |
Correct |
426 ms |
31916 KB |
Output is correct |