# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
339773 |
2020-12-26T07:45:47 Z |
Kerim |
Race (IOI11_race) |
C++17 |
|
452 ms |
73236 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 wr cout<<"----------------"<<endl;
#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
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
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;
}
/*
static int N, K;
static int H[MAXN][2];
static int L[MAXN];
static int solution;
inline
void my_assert(int e) {if (!e) abort();}
void read_input(){
int i;
my_assert(2==scanf("%d %d",&N,&K));
for(i=0; i<N-1; i++)
my_assert(3==scanf("%d %d %d",&H[i][0],&H[i][1],&L[i]));
my_assert(1==scanf("%d",&solution));
}
int main(){
freopen("grader.in.3","r",stdin);
int ans;
read_input();
ans = best_path(N,K,H,L);
if(ans==solution)
printf("Correct.\n");
else
printf("Incorrect. Returned %d, Expected %d.\n",ans,solution);
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
14444 KB |
Output is correct |
2 |
Correct |
9 ms |
14444 KB |
Output is correct |
3 |
Correct |
11 ms |
14592 KB |
Output is correct |
4 |
Correct |
9 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
9 ms |
14444 KB |
Output is correct |
7 |
Correct |
9 ms |
14444 KB |
Output is correct |
8 |
Correct |
9 ms |
14444 KB |
Output is correct |
9 |
Correct |
11 ms |
14444 KB |
Output is correct |
10 |
Correct |
9 ms |
14444 KB |
Output is correct |
11 |
Correct |
11 ms |
14444 KB |
Output is correct |
12 |
Correct |
10 ms |
14444 KB |
Output is correct |
13 |
Correct |
9 ms |
14444 KB |
Output is correct |
14 |
Correct |
9 ms |
14444 KB |
Output is correct |
15 |
Correct |
9 ms |
14444 KB |
Output is correct |
16 |
Correct |
9 ms |
14444 KB |
Output is correct |
17 |
Correct |
9 ms |
14444 KB |
Output is correct |
18 |
Correct |
9 ms |
14444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
14444 KB |
Output is correct |
2 |
Correct |
9 ms |
14444 KB |
Output is correct |
3 |
Correct |
11 ms |
14592 KB |
Output is correct |
4 |
Correct |
9 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
9 ms |
14444 KB |
Output is correct |
7 |
Correct |
9 ms |
14444 KB |
Output is correct |
8 |
Correct |
9 ms |
14444 KB |
Output is correct |
9 |
Correct |
11 ms |
14444 KB |
Output is correct |
10 |
Correct |
9 ms |
14444 KB |
Output is correct |
11 |
Correct |
11 ms |
14444 KB |
Output is correct |
12 |
Correct |
10 ms |
14444 KB |
Output is correct |
13 |
Correct |
9 ms |
14444 KB |
Output is correct |
14 |
Correct |
9 ms |
14444 KB |
Output is correct |
15 |
Correct |
9 ms |
14444 KB |
Output is correct |
16 |
Correct |
9 ms |
14444 KB |
Output is correct |
17 |
Correct |
9 ms |
14444 KB |
Output is correct |
18 |
Correct |
9 ms |
14444 KB |
Output is correct |
19 |
Correct |
9 ms |
14444 KB |
Output is correct |
20 |
Correct |
10 ms |
14444 KB |
Output is correct |
21 |
Correct |
10 ms |
14572 KB |
Output is correct |
22 |
Correct |
11 ms |
14572 KB |
Output is correct |
23 |
Correct |
11 ms |
14572 KB |
Output is correct |
24 |
Correct |
10 ms |
14572 KB |
Output is correct |
25 |
Correct |
10 ms |
14572 KB |
Output is correct |
26 |
Correct |
10 ms |
14572 KB |
Output is correct |
27 |
Correct |
10 ms |
14444 KB |
Output is correct |
28 |
Correct |
10 ms |
14572 KB |
Output is correct |
29 |
Correct |
10 ms |
14572 KB |
Output is correct |
30 |
Correct |
10 ms |
14572 KB |
Output is correct |
31 |
Correct |
11 ms |
14572 KB |
Output is correct |
32 |
Correct |
11 ms |
14592 KB |
Output is correct |
33 |
Correct |
11 ms |
14572 KB |
Output is correct |
34 |
Correct |
10 ms |
14572 KB |
Output is correct |
35 |
Correct |
10 ms |
14572 KB |
Output is correct |
36 |
Correct |
10 ms |
14572 KB |
Output is correct |
37 |
Correct |
10 ms |
14592 KB |
Output is correct |
38 |
Correct |
10 ms |
14572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
14444 KB |
Output is correct |
2 |
Correct |
9 ms |
14444 KB |
Output is correct |
3 |
Correct |
11 ms |
14592 KB |
Output is correct |
4 |
Correct |
9 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
9 ms |
14444 KB |
Output is correct |
7 |
Correct |
9 ms |
14444 KB |
Output is correct |
8 |
Correct |
9 ms |
14444 KB |
Output is correct |
9 |
Correct |
11 ms |
14444 KB |
Output is correct |
10 |
Correct |
9 ms |
14444 KB |
Output is correct |
11 |
Correct |
11 ms |
14444 KB |
Output is correct |
12 |
Correct |
10 ms |
14444 KB |
Output is correct |
13 |
Correct |
9 ms |
14444 KB |
Output is correct |
14 |
Correct |
9 ms |
14444 KB |
Output is correct |
15 |
Correct |
9 ms |
14444 KB |
Output is correct |
16 |
Correct |
9 ms |
14444 KB |
Output is correct |
17 |
Correct |
9 ms |
14444 KB |
Output is correct |
18 |
Correct |
9 ms |
14444 KB |
Output is correct |
19 |
Correct |
138 ms |
21860 KB |
Output is correct |
20 |
Correct |
137 ms |
21996 KB |
Output is correct |
21 |
Correct |
131 ms |
21740 KB |
Output is correct |
22 |
Correct |
137 ms |
21740 KB |
Output is correct |
23 |
Correct |
165 ms |
22636 KB |
Output is correct |
24 |
Correct |
135 ms |
21740 KB |
Output is correct |
25 |
Correct |
127 ms |
43244 KB |
Output is correct |
26 |
Correct |
94 ms |
44396 KB |
Output is correct |
27 |
Correct |
250 ms |
32236 KB |
Output is correct |
28 |
Correct |
269 ms |
73236 KB |
Output is correct |
29 |
Correct |
283 ms |
65772 KB |
Output is correct |
30 |
Correct |
246 ms |
32364 KB |
Output is correct |
31 |
Correct |
232 ms |
32236 KB |
Output is correct |
32 |
Correct |
287 ms |
32328 KB |
Output is correct |
33 |
Correct |
213 ms |
28396 KB |
Output is correct |
34 |
Correct |
362 ms |
42052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
14444 KB |
Output is correct |
2 |
Correct |
9 ms |
14444 KB |
Output is correct |
3 |
Correct |
11 ms |
14592 KB |
Output is correct |
4 |
Correct |
9 ms |
14444 KB |
Output is correct |
5 |
Correct |
10 ms |
14444 KB |
Output is correct |
6 |
Correct |
9 ms |
14444 KB |
Output is correct |
7 |
Correct |
9 ms |
14444 KB |
Output is correct |
8 |
Correct |
9 ms |
14444 KB |
Output is correct |
9 |
Correct |
11 ms |
14444 KB |
Output is correct |
10 |
Correct |
9 ms |
14444 KB |
Output is correct |
11 |
Correct |
11 ms |
14444 KB |
Output is correct |
12 |
Correct |
10 ms |
14444 KB |
Output is correct |
13 |
Correct |
9 ms |
14444 KB |
Output is correct |
14 |
Correct |
9 ms |
14444 KB |
Output is correct |
15 |
Correct |
9 ms |
14444 KB |
Output is correct |
16 |
Correct |
9 ms |
14444 KB |
Output is correct |
17 |
Correct |
9 ms |
14444 KB |
Output is correct |
18 |
Correct |
9 ms |
14444 KB |
Output is correct |
19 |
Correct |
9 ms |
14444 KB |
Output is correct |
20 |
Correct |
10 ms |
14444 KB |
Output is correct |
21 |
Correct |
10 ms |
14572 KB |
Output is correct |
22 |
Correct |
11 ms |
14572 KB |
Output is correct |
23 |
Correct |
11 ms |
14572 KB |
Output is correct |
24 |
Correct |
10 ms |
14572 KB |
Output is correct |
25 |
Correct |
10 ms |
14572 KB |
Output is correct |
26 |
Correct |
10 ms |
14572 KB |
Output is correct |
27 |
Correct |
10 ms |
14444 KB |
Output is correct |
28 |
Correct |
10 ms |
14572 KB |
Output is correct |
29 |
Correct |
10 ms |
14572 KB |
Output is correct |
30 |
Correct |
10 ms |
14572 KB |
Output is correct |
31 |
Correct |
11 ms |
14572 KB |
Output is correct |
32 |
Correct |
11 ms |
14592 KB |
Output is correct |
33 |
Correct |
11 ms |
14572 KB |
Output is correct |
34 |
Correct |
10 ms |
14572 KB |
Output is correct |
35 |
Correct |
10 ms |
14572 KB |
Output is correct |
36 |
Correct |
10 ms |
14572 KB |
Output is correct |
37 |
Correct |
10 ms |
14592 KB |
Output is correct |
38 |
Correct |
10 ms |
14572 KB |
Output is correct |
39 |
Correct |
138 ms |
21860 KB |
Output is correct |
40 |
Correct |
137 ms |
21996 KB |
Output is correct |
41 |
Correct |
131 ms |
21740 KB |
Output is correct |
42 |
Correct |
137 ms |
21740 KB |
Output is correct |
43 |
Correct |
165 ms |
22636 KB |
Output is correct |
44 |
Correct |
135 ms |
21740 KB |
Output is correct |
45 |
Correct |
127 ms |
43244 KB |
Output is correct |
46 |
Correct |
94 ms |
44396 KB |
Output is correct |
47 |
Correct |
250 ms |
32236 KB |
Output is correct |
48 |
Correct |
269 ms |
73236 KB |
Output is correct |
49 |
Correct |
283 ms |
65772 KB |
Output is correct |
50 |
Correct |
246 ms |
32364 KB |
Output is correct |
51 |
Correct |
232 ms |
32236 KB |
Output is correct |
52 |
Correct |
287 ms |
32328 KB |
Output is correct |
53 |
Correct |
213 ms |
28396 KB |
Output is correct |
54 |
Correct |
362 ms |
42052 KB |
Output is correct |
55 |
Correct |
22 ms |
15872 KB |
Output is correct |
56 |
Correct |
17 ms |
15212 KB |
Output is correct |
57 |
Correct |
75 ms |
21740 KB |
Output is correct |
58 |
Correct |
58 ms |
21344 KB |
Output is correct |
59 |
Correct |
95 ms |
44396 KB |
Output is correct |
60 |
Correct |
273 ms |
63980 KB |
Output is correct |
61 |
Correct |
272 ms |
36460 KB |
Output is correct |
62 |
Correct |
240 ms |
32492 KB |
Output is correct |
63 |
Correct |
268 ms |
32364 KB |
Output is correct |
64 |
Correct |
452 ms |
42348 KB |
Output is correct |
65 |
Correct |
437 ms |
42604 KB |
Output is correct |
66 |
Correct |
262 ms |
71308 KB |
Output is correct |
67 |
Correct |
184 ms |
29660 KB |
Output is correct |
68 |
Correct |
371 ms |
41964 KB |
Output is correct |
69 |
Correct |
387 ms |
46956 KB |
Output is correct |
70 |
Correct |
332 ms |
40812 KB |
Output is correct |