# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
138354 |
2019-07-29T19:43:56 Z |
MrBrionix |
Race (IOI11_race) |
C++14 |
|
728 ms |
106356 KB |
#include "race.h"
#include <stdio.h>
#include <stdlib.h>
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 500000
vector<int> grafo[200005],peso[200005];
long long k,n,siz[200005],ans;
long long lazy[200005],lazyval[200005];
map<long long,long long> sol[200005];
/*4 3
0 1 1
1 2 2
1 3 4
-----
11 19
0 1 3
0 2 4
2 3 5
3 4 4
4 5 6
0 6 3
6 7 2
6 8 5
8 9 6
8 10 7
*/
void dfs(int nodo,int last){
//cout<<nodo<<" arrivo da "<<last<<endl;
siz[nodo]=1;
int best=0,num;
long long val=0;
for(int i=0;i<grafo[nodo].size();i++){
if(grafo[nodo][i]!=last){
//cout<<"chiamo "<<grafo[nodo][i]<<" "<<nodo<<" "<<last<<endl;
dfs(grafo[nodo][i],nodo);
siz[nodo]+=siz[grafo[nodo][i]];
if(siz[grafo[nodo][i]]>best){
swap(sol[nodo],sol[grafo[nodo][i]]);
lazy[nodo]--;
lazy[grafo[nodo][i]]++;
swap(lazy[nodo],lazy[grafo[nodo][i]]);
lazyval[nodo]-=peso[nodo][i];
lazyval[grafo[nodo][i]]+=peso[nodo][i];
swap(lazyval[nodo],lazyval[grafo[nodo][i]]);
best=siz[grafo[nodo][i]];
}
}
}
sol[nodo][0-lazyval[nodo]]=0-lazy[nodo];
for(int i=0;i<grafo[nodo].size();i++){
if(grafo[nodo][i]!=last){
for(auto j : sol[grafo[nodo][i]]){
num=j.second+lazy[grafo[nodo][i]]+1;
val=j.first+lazyval[grafo[nodo][i]]+peso[nodo][i];
if(sol[nodo].find(k-val-lazyval[nodo])!=sol[nodo].end())
ans=min(ans,num+sol[nodo][k-val-lazyval[nodo]]+lazy[nodo]);
}
for(auto j : sol[grafo[nodo][i]]){
num=j.second+lazy[grafo[nodo][i]]+1;
val=j.first+lazyval[grafo[nodo][i]]+peso[nodo][i];
//cout<<"dal figlio "<<grafo[nodo][i]<<" prendo "<<j.second+lazy[grafo[nodo][i]]<<"e "<<j.first+lazyval[grafo[nodo][i]]<<endl;
if(sol[nodo].find(val-lazyval[nodo])!=sol[nodo].end())
sol[nodo][val-lazyval[nodo]]=min(sol[nodo][val-lazyval[nodo]],num-lazy[nodo]);
else sol[nodo][val-lazyval[nodo]]=num-lazy[nodo];
}
}
}
if(sol[nodo].find(k-lazyval[nodo])!=sol[nodo].end())ans=min(ans,sol[nodo][k-lazyval[nodo]]+lazy[nodo]);
/*cout<<"info nodo "<<nodo<<":"<<endl;
for(auto i : sol[nodo]){
cout<<i.first+lazyval[nodo]<<" "<<i.second+lazy[nodo]<<endl;
}
cout<<"fine -----------"<<endl;*/
}
int best_path(int N, int K, int H[][2], int L[]){
n=N;
k=K;
ans=10000000ll;
for(int i=0;i<n-1;i++){
grafo[H[i][0]].push_back(H[i][1]);
grafo[H[i][1]].push_back(H[i][0]);
peso[H[i][0]].push_back(L[i]);
peso[H[i][1]].push_back(L[i]);
}
dfs(0,-1);
if(ans==10000000ll)return -1;
return ans;
}
/*
static int N, K;
static int H[MAX_N][2];
static int L[MAX_N];
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()
{
int ans;
read_input();
ans = best_path(N,K,H,L);
cout<<ans<<endl;
if(ans==solution)
printf("Correct.\n");
else
printf("Incorrect. Returned %d, Expected %d.\n",ans,solution);
return 0;
}*/
Compilation message
race.cpp: In function 'void dfs(int, int)':
race.cpp:41:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<grafo[nodo].size();i++){
~^~~~~~~~~~~~~~~~~~~
race.cpp:65:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<grafo[nodo].size();i++){
~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
19320 KB |
Output is correct |
2 |
Correct |
19 ms |
19192 KB |
Output is correct |
3 |
Correct |
20 ms |
19192 KB |
Output is correct |
4 |
Correct |
19 ms |
19192 KB |
Output is correct |
5 |
Correct |
19 ms |
19192 KB |
Output is correct |
6 |
Correct |
19 ms |
19192 KB |
Output is correct |
7 |
Correct |
20 ms |
19320 KB |
Output is correct |
8 |
Correct |
19 ms |
19192 KB |
Output is correct |
9 |
Correct |
19 ms |
19192 KB |
Output is correct |
10 |
Correct |
23 ms |
19192 KB |
Output is correct |
11 |
Correct |
22 ms |
19192 KB |
Output is correct |
12 |
Correct |
23 ms |
19192 KB |
Output is correct |
13 |
Correct |
19 ms |
19192 KB |
Output is correct |
14 |
Correct |
20 ms |
19192 KB |
Output is correct |
15 |
Correct |
19 ms |
19192 KB |
Output is correct |
16 |
Correct |
23 ms |
19192 KB |
Output is correct |
17 |
Correct |
19 ms |
19192 KB |
Output is correct |
18 |
Correct |
22 ms |
19192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
19320 KB |
Output is correct |
2 |
Correct |
19 ms |
19192 KB |
Output is correct |
3 |
Correct |
20 ms |
19192 KB |
Output is correct |
4 |
Correct |
19 ms |
19192 KB |
Output is correct |
5 |
Correct |
19 ms |
19192 KB |
Output is correct |
6 |
Correct |
19 ms |
19192 KB |
Output is correct |
7 |
Correct |
20 ms |
19320 KB |
Output is correct |
8 |
Correct |
19 ms |
19192 KB |
Output is correct |
9 |
Correct |
19 ms |
19192 KB |
Output is correct |
10 |
Correct |
23 ms |
19192 KB |
Output is correct |
11 |
Correct |
22 ms |
19192 KB |
Output is correct |
12 |
Correct |
23 ms |
19192 KB |
Output is correct |
13 |
Correct |
19 ms |
19192 KB |
Output is correct |
14 |
Correct |
20 ms |
19192 KB |
Output is correct |
15 |
Correct |
19 ms |
19192 KB |
Output is correct |
16 |
Correct |
23 ms |
19192 KB |
Output is correct |
17 |
Correct |
19 ms |
19192 KB |
Output is correct |
18 |
Correct |
22 ms |
19192 KB |
Output is correct |
19 |
Correct |
18 ms |
19064 KB |
Output is correct |
20 |
Correct |
19 ms |
19192 KB |
Output is correct |
21 |
Correct |
20 ms |
19448 KB |
Output is correct |
22 |
Correct |
20 ms |
19448 KB |
Output is correct |
23 |
Correct |
20 ms |
19448 KB |
Output is correct |
24 |
Correct |
21 ms |
19448 KB |
Output is correct |
25 |
Correct |
20 ms |
19448 KB |
Output is correct |
26 |
Correct |
21 ms |
19448 KB |
Output is correct |
27 |
Correct |
21 ms |
19320 KB |
Output is correct |
28 |
Correct |
21 ms |
19448 KB |
Output is correct |
29 |
Correct |
21 ms |
19448 KB |
Output is correct |
30 |
Correct |
21 ms |
19448 KB |
Output is correct |
31 |
Correct |
24 ms |
19448 KB |
Output is correct |
32 |
Correct |
25 ms |
19448 KB |
Output is correct |
33 |
Correct |
25 ms |
19448 KB |
Output is correct |
34 |
Correct |
20 ms |
19320 KB |
Output is correct |
35 |
Correct |
24 ms |
19360 KB |
Output is correct |
36 |
Correct |
20 ms |
19320 KB |
Output is correct |
37 |
Correct |
20 ms |
19320 KB |
Output is correct |
38 |
Correct |
20 ms |
19320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
19320 KB |
Output is correct |
2 |
Correct |
19 ms |
19192 KB |
Output is correct |
3 |
Correct |
20 ms |
19192 KB |
Output is correct |
4 |
Correct |
19 ms |
19192 KB |
Output is correct |
5 |
Correct |
19 ms |
19192 KB |
Output is correct |
6 |
Correct |
19 ms |
19192 KB |
Output is correct |
7 |
Correct |
20 ms |
19320 KB |
Output is correct |
8 |
Correct |
19 ms |
19192 KB |
Output is correct |
9 |
Correct |
19 ms |
19192 KB |
Output is correct |
10 |
Correct |
23 ms |
19192 KB |
Output is correct |
11 |
Correct |
22 ms |
19192 KB |
Output is correct |
12 |
Correct |
23 ms |
19192 KB |
Output is correct |
13 |
Correct |
19 ms |
19192 KB |
Output is correct |
14 |
Correct |
20 ms |
19192 KB |
Output is correct |
15 |
Correct |
19 ms |
19192 KB |
Output is correct |
16 |
Correct |
23 ms |
19192 KB |
Output is correct |
17 |
Correct |
19 ms |
19192 KB |
Output is correct |
18 |
Correct |
22 ms |
19192 KB |
Output is correct |
19 |
Correct |
216 ms |
41508 KB |
Output is correct |
20 |
Correct |
209 ms |
41464 KB |
Output is correct |
21 |
Correct |
239 ms |
41440 KB |
Output is correct |
22 |
Correct |
278 ms |
41740 KB |
Output is correct |
23 |
Correct |
276 ms |
54836 KB |
Output is correct |
24 |
Correct |
232 ms |
48164 KB |
Output is correct |
25 |
Correct |
162 ms |
40948 KB |
Output is correct |
26 |
Correct |
98 ms |
49020 KB |
Output is correct |
27 |
Correct |
431 ms |
55724 KB |
Output is correct |
28 |
Correct |
483 ms |
91928 KB |
Output is correct |
29 |
Correct |
506 ms |
90104 KB |
Output is correct |
30 |
Correct |
389 ms |
55756 KB |
Output is correct |
31 |
Correct |
512 ms |
55848 KB |
Output is correct |
32 |
Correct |
591 ms |
55928 KB |
Output is correct |
33 |
Correct |
413 ms |
54648 KB |
Output is correct |
34 |
Correct |
636 ms |
87400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
19320 KB |
Output is correct |
2 |
Correct |
19 ms |
19192 KB |
Output is correct |
3 |
Correct |
20 ms |
19192 KB |
Output is correct |
4 |
Correct |
19 ms |
19192 KB |
Output is correct |
5 |
Correct |
19 ms |
19192 KB |
Output is correct |
6 |
Correct |
19 ms |
19192 KB |
Output is correct |
7 |
Correct |
20 ms |
19320 KB |
Output is correct |
8 |
Correct |
19 ms |
19192 KB |
Output is correct |
9 |
Correct |
19 ms |
19192 KB |
Output is correct |
10 |
Correct |
23 ms |
19192 KB |
Output is correct |
11 |
Correct |
22 ms |
19192 KB |
Output is correct |
12 |
Correct |
23 ms |
19192 KB |
Output is correct |
13 |
Correct |
19 ms |
19192 KB |
Output is correct |
14 |
Correct |
20 ms |
19192 KB |
Output is correct |
15 |
Correct |
19 ms |
19192 KB |
Output is correct |
16 |
Correct |
23 ms |
19192 KB |
Output is correct |
17 |
Correct |
19 ms |
19192 KB |
Output is correct |
18 |
Correct |
22 ms |
19192 KB |
Output is correct |
19 |
Correct |
18 ms |
19064 KB |
Output is correct |
20 |
Correct |
19 ms |
19192 KB |
Output is correct |
21 |
Correct |
20 ms |
19448 KB |
Output is correct |
22 |
Correct |
20 ms |
19448 KB |
Output is correct |
23 |
Correct |
20 ms |
19448 KB |
Output is correct |
24 |
Correct |
21 ms |
19448 KB |
Output is correct |
25 |
Correct |
20 ms |
19448 KB |
Output is correct |
26 |
Correct |
21 ms |
19448 KB |
Output is correct |
27 |
Correct |
21 ms |
19320 KB |
Output is correct |
28 |
Correct |
21 ms |
19448 KB |
Output is correct |
29 |
Correct |
21 ms |
19448 KB |
Output is correct |
30 |
Correct |
21 ms |
19448 KB |
Output is correct |
31 |
Correct |
24 ms |
19448 KB |
Output is correct |
32 |
Correct |
25 ms |
19448 KB |
Output is correct |
33 |
Correct |
25 ms |
19448 KB |
Output is correct |
34 |
Correct |
20 ms |
19320 KB |
Output is correct |
35 |
Correct |
24 ms |
19360 KB |
Output is correct |
36 |
Correct |
20 ms |
19320 KB |
Output is correct |
37 |
Correct |
20 ms |
19320 KB |
Output is correct |
38 |
Correct |
20 ms |
19320 KB |
Output is correct |
39 |
Correct |
216 ms |
41508 KB |
Output is correct |
40 |
Correct |
209 ms |
41464 KB |
Output is correct |
41 |
Correct |
239 ms |
41440 KB |
Output is correct |
42 |
Correct |
278 ms |
41740 KB |
Output is correct |
43 |
Correct |
276 ms |
54836 KB |
Output is correct |
44 |
Correct |
232 ms |
48164 KB |
Output is correct |
45 |
Correct |
162 ms |
40948 KB |
Output is correct |
46 |
Correct |
98 ms |
49020 KB |
Output is correct |
47 |
Correct |
431 ms |
55724 KB |
Output is correct |
48 |
Correct |
483 ms |
91928 KB |
Output is correct |
49 |
Correct |
506 ms |
90104 KB |
Output is correct |
50 |
Correct |
389 ms |
55756 KB |
Output is correct |
51 |
Correct |
512 ms |
55848 KB |
Output is correct |
52 |
Correct |
591 ms |
55928 KB |
Output is correct |
53 |
Correct |
413 ms |
54648 KB |
Output is correct |
54 |
Correct |
636 ms |
87400 KB |
Output is correct |
55 |
Correct |
49 ms |
22368 KB |
Output is correct |
56 |
Correct |
37 ms |
21112 KB |
Output is correct |
57 |
Correct |
128 ms |
39908 KB |
Output is correct |
58 |
Correct |
99 ms |
35468 KB |
Output is correct |
59 |
Correct |
148 ms |
55288 KB |
Output is correct |
60 |
Correct |
462 ms |
90408 KB |
Output is correct |
61 |
Correct |
499 ms |
59384 KB |
Output is correct |
62 |
Correct |
485 ms |
55672 KB |
Output is correct |
63 |
Correct |
585 ms |
55928 KB |
Output is correct |
64 |
Correct |
718 ms |
105420 KB |
Output is correct |
65 |
Correct |
728 ms |
106356 KB |
Output is correct |
66 |
Correct |
471 ms |
86064 KB |
Output is correct |
67 |
Correct |
381 ms |
56392 KB |
Output is correct |
68 |
Correct |
607 ms |
74340 KB |
Output is correct |
69 |
Correct |
625 ms |
75260 KB |
Output is correct |
70 |
Correct |
582 ms |
72184 KB |
Output is correct |