# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
223370 |
2020-04-15T08:12:38 Z |
wendy_virgo |
Race (IOI11_race) |
C++14 |
|
1025 ms |
33400 KB |
#include <bits/stdc++.h>
using namespace std;
template<typename TH>
void _dbg(const char* sdbg, TH h)
{
cerr << sdbg << " = " << h << "\n";
}
template<typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t)
{
while (*sdbg != ',') cerr << *sdbg++;
cerr << " = " << h << ",";
_dbg(sdbg + 1, t...);
}
#define db(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define chkpt cerr << "--- Checkpoint here ---\n";
const int N=2e5+5,K=1e6+6,INF=1e9,LOG_N=20;
struct Edge{
int u,v,w;
int Adj(int x){
return u^v^x;
}
};
int n,k;
Edge edgeList[N];
vector<int> g[N];
bool del[N];
int sz[N],ans=INF,f[K];
void DFS_Size(int u,int fa){
sz[u]=1;
for(int id:g[u]){
int v=edgeList[id].Adj(u);
if(v!=fa&&!del[v]){
DFS_Size(v,u);
sz[u]+=sz[v];
}
}
}
int FindCentroid(int u,int fa,int curSz){
int maxSize=0,big=0;
for(int id:g[u]){
int v=edgeList[id].Adj(u);
if(v!=fa&&!del[v]&&sz[v]>maxSize){
maxSize=sz[v];
big=v;
}
}
if(maxSize<=curSz/2){
return u;
}
return FindCentroid(big,u,curSz);
}
void DFS_UpdateAns(int u,int fa,int64_t s,int d){
if(s<=k&&f[k-s]!=INF){
ans=min(ans,f[k-s]+d);
}
for(int id:g[u]){
int v=edgeList[id].Adj(u),w=edgeList[id].w;
if(!del[v]&&v!=fa){
DFS_UpdateAns(v,u,s+w,d+1);
}
}
}
void DFS_UpdateF(int u,int fa,int64_t s,int d){
if(s<=k){
f[s]=min(f[s],d);
}
for(int id:g[u]){
int v=edgeList[id].Adj(u),w=edgeList[id].w;
if(!del[v]&&v!=fa){
DFS_UpdateF(v,u,s+w,d+1);
}
}
}
void DFS_Reset(int u,int fa,int64_t s,int d){
if(s<=k){
f[s]=INF;
}
for(int id:g[u]){
int v=edgeList[id].Adj(u),w=edgeList[id].w;
if(!del[v]&&v!=fa){
DFS_Reset(v,u,s+w,d+1);
}
}
}
int BuildCentroidTree(int u){
DFS_Size(u,-1);
int cen=FindCentroid(u,-1,sz[u]);
for(int id:g[cen]){
int v=edgeList[id].Adj(cen),w=edgeList[id].w;
if(!del[v]){
f[0]=0;
DFS_UpdateAns(v,cen,w,1);
DFS_UpdateF(v,cen,w,1);
}
}
DFS_Reset(cen,cen,0,0);
del[cen]=true;
for(int id:g[cen]){
int v=edgeList[id].Adj(cen);
if(!del[v]){
int tmp=BuildCentroidTree(v);
// cout<<cen<<' '<<tmp<<'\n';
}
}
return cen;
}
int Solve(){
for(int i=0;i<K;++i){
f[i]=INF;
}
BuildCentroidTree(1);
return ans==INF?-1:ans;
}
int best_path(int N,int K,int H[][2],int L[])
{
n=N;
k=K;
for(int i=0;i<=n-2;++i){
int u=H[i][0]+1,v=H[i][1]+1;
g[u].push_back(i+1);
g[v].push_back(i+1);
edgeList[i+1]={u,v,0};
}
for(int i=0;i<=n-2;++i){
edgeList[i+1].w=L[i];
}
return Solve();
}
//int main()
//{
//// freopen("IOI11_race.inp","r",stdin);
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cin>>n>>k;
// for(int i=1;i<=n-1;++i){
// int u,v,w;
// cin>>u>>v>>w;
// u++;
// v++;
//// cout<<u<<' '<<v<<'\n';
// g[u].push_back(i);
// g[v].push_back(i);
// edgeList[i]={u,v,w};
// }
//// for(int i=1;i<=n-1;++i){
//// cin>>edgeList[i].w;
//// }
// cout<<Solve();
// return 0;
//}
Compilation message
race.cpp: In function 'int BuildCentroidTree(int)':
race.cpp:116:17: warning: unused variable 'tmp' [-Wunused-variable]
int tmp=BuildCentroidTree(v);
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8960 KB |
Output is correct |
2 |
Correct |
9 ms |
8960 KB |
Output is correct |
3 |
Correct |
10 ms |
8960 KB |
Output is correct |
4 |
Correct |
10 ms |
8960 KB |
Output is correct |
5 |
Correct |
10 ms |
8960 KB |
Output is correct |
6 |
Correct |
10 ms |
8960 KB |
Output is correct |
7 |
Correct |
10 ms |
8960 KB |
Output is correct |
8 |
Correct |
10 ms |
8960 KB |
Output is correct |
9 |
Correct |
11 ms |
8960 KB |
Output is correct |
10 |
Correct |
12 ms |
8960 KB |
Output is correct |
11 |
Correct |
10 ms |
8960 KB |
Output is correct |
12 |
Correct |
10 ms |
8960 KB |
Output is correct |
13 |
Correct |
9 ms |
8960 KB |
Output is correct |
14 |
Correct |
10 ms |
8960 KB |
Output is correct |
15 |
Correct |
10 ms |
8960 KB |
Output is correct |
16 |
Correct |
10 ms |
8960 KB |
Output is correct |
17 |
Correct |
10 ms |
8960 KB |
Output is correct |
18 |
Correct |
10 ms |
8960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8960 KB |
Output is correct |
2 |
Correct |
9 ms |
8960 KB |
Output is correct |
3 |
Correct |
10 ms |
8960 KB |
Output is correct |
4 |
Correct |
10 ms |
8960 KB |
Output is correct |
5 |
Correct |
10 ms |
8960 KB |
Output is correct |
6 |
Correct |
10 ms |
8960 KB |
Output is correct |
7 |
Correct |
10 ms |
8960 KB |
Output is correct |
8 |
Correct |
10 ms |
8960 KB |
Output is correct |
9 |
Correct |
11 ms |
8960 KB |
Output is correct |
10 |
Correct |
12 ms |
8960 KB |
Output is correct |
11 |
Correct |
10 ms |
8960 KB |
Output is correct |
12 |
Correct |
10 ms |
8960 KB |
Output is correct |
13 |
Correct |
9 ms |
8960 KB |
Output is correct |
14 |
Correct |
10 ms |
8960 KB |
Output is correct |
15 |
Correct |
10 ms |
8960 KB |
Output is correct |
16 |
Correct |
10 ms |
8960 KB |
Output is correct |
17 |
Correct |
10 ms |
8960 KB |
Output is correct |
18 |
Correct |
10 ms |
8960 KB |
Output is correct |
19 |
Correct |
10 ms |
8960 KB |
Output is correct |
20 |
Correct |
10 ms |
8960 KB |
Output is correct |
21 |
Correct |
10 ms |
8960 KB |
Output is correct |
22 |
Correct |
13 ms |
8960 KB |
Output is correct |
23 |
Correct |
11 ms |
9088 KB |
Output is correct |
24 |
Correct |
11 ms |
8960 KB |
Output is correct |
25 |
Correct |
10 ms |
8960 KB |
Output is correct |
26 |
Correct |
11 ms |
8960 KB |
Output is correct |
27 |
Correct |
10 ms |
8960 KB |
Output is correct |
28 |
Correct |
11 ms |
8960 KB |
Output is correct |
29 |
Correct |
11 ms |
8960 KB |
Output is correct |
30 |
Correct |
11 ms |
8960 KB |
Output is correct |
31 |
Correct |
11 ms |
9088 KB |
Output is correct |
32 |
Correct |
11 ms |
9088 KB |
Output is correct |
33 |
Correct |
11 ms |
8960 KB |
Output is correct |
34 |
Correct |
11 ms |
8960 KB |
Output is correct |
35 |
Correct |
11 ms |
8960 KB |
Output is correct |
36 |
Correct |
11 ms |
9088 KB |
Output is correct |
37 |
Correct |
11 ms |
8960 KB |
Output is correct |
38 |
Correct |
10 ms |
8960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8960 KB |
Output is correct |
2 |
Correct |
9 ms |
8960 KB |
Output is correct |
3 |
Correct |
10 ms |
8960 KB |
Output is correct |
4 |
Correct |
10 ms |
8960 KB |
Output is correct |
5 |
Correct |
10 ms |
8960 KB |
Output is correct |
6 |
Correct |
10 ms |
8960 KB |
Output is correct |
7 |
Correct |
10 ms |
8960 KB |
Output is correct |
8 |
Correct |
10 ms |
8960 KB |
Output is correct |
9 |
Correct |
11 ms |
8960 KB |
Output is correct |
10 |
Correct |
12 ms |
8960 KB |
Output is correct |
11 |
Correct |
10 ms |
8960 KB |
Output is correct |
12 |
Correct |
10 ms |
8960 KB |
Output is correct |
13 |
Correct |
9 ms |
8960 KB |
Output is correct |
14 |
Correct |
10 ms |
8960 KB |
Output is correct |
15 |
Correct |
10 ms |
8960 KB |
Output is correct |
16 |
Correct |
10 ms |
8960 KB |
Output is correct |
17 |
Correct |
10 ms |
8960 KB |
Output is correct |
18 |
Correct |
10 ms |
8960 KB |
Output is correct |
19 |
Correct |
308 ms |
14968 KB |
Output is correct |
20 |
Correct |
305 ms |
14968 KB |
Output is correct |
21 |
Correct |
292 ms |
14968 KB |
Output is correct |
22 |
Correct |
265 ms |
15144 KB |
Output is correct |
23 |
Correct |
168 ms |
14968 KB |
Output is correct |
24 |
Correct |
98 ms |
15096 KB |
Output is correct |
25 |
Correct |
241 ms |
18268 KB |
Output is correct |
26 |
Correct |
144 ms |
21240 KB |
Output is correct |
27 |
Correct |
356 ms |
21496 KB |
Output is correct |
28 |
Correct |
699 ms |
33400 KB |
Output is correct |
29 |
Correct |
666 ms |
32640 KB |
Output is correct |
30 |
Correct |
340 ms |
21496 KB |
Output is correct |
31 |
Correct |
337 ms |
21696 KB |
Output is correct |
32 |
Correct |
477 ms |
21484 KB |
Output is correct |
33 |
Correct |
441 ms |
20984 KB |
Output is correct |
34 |
Correct |
467 ms |
21116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8960 KB |
Output is correct |
2 |
Correct |
9 ms |
8960 KB |
Output is correct |
3 |
Correct |
10 ms |
8960 KB |
Output is correct |
4 |
Correct |
10 ms |
8960 KB |
Output is correct |
5 |
Correct |
10 ms |
8960 KB |
Output is correct |
6 |
Correct |
10 ms |
8960 KB |
Output is correct |
7 |
Correct |
10 ms |
8960 KB |
Output is correct |
8 |
Correct |
10 ms |
8960 KB |
Output is correct |
9 |
Correct |
11 ms |
8960 KB |
Output is correct |
10 |
Correct |
12 ms |
8960 KB |
Output is correct |
11 |
Correct |
10 ms |
8960 KB |
Output is correct |
12 |
Correct |
10 ms |
8960 KB |
Output is correct |
13 |
Correct |
9 ms |
8960 KB |
Output is correct |
14 |
Correct |
10 ms |
8960 KB |
Output is correct |
15 |
Correct |
10 ms |
8960 KB |
Output is correct |
16 |
Correct |
10 ms |
8960 KB |
Output is correct |
17 |
Correct |
10 ms |
8960 KB |
Output is correct |
18 |
Correct |
10 ms |
8960 KB |
Output is correct |
19 |
Correct |
10 ms |
8960 KB |
Output is correct |
20 |
Correct |
10 ms |
8960 KB |
Output is correct |
21 |
Correct |
10 ms |
8960 KB |
Output is correct |
22 |
Correct |
13 ms |
8960 KB |
Output is correct |
23 |
Correct |
11 ms |
9088 KB |
Output is correct |
24 |
Correct |
11 ms |
8960 KB |
Output is correct |
25 |
Correct |
10 ms |
8960 KB |
Output is correct |
26 |
Correct |
11 ms |
8960 KB |
Output is correct |
27 |
Correct |
10 ms |
8960 KB |
Output is correct |
28 |
Correct |
11 ms |
8960 KB |
Output is correct |
29 |
Correct |
11 ms |
8960 KB |
Output is correct |
30 |
Correct |
11 ms |
8960 KB |
Output is correct |
31 |
Correct |
11 ms |
9088 KB |
Output is correct |
32 |
Correct |
11 ms |
9088 KB |
Output is correct |
33 |
Correct |
11 ms |
8960 KB |
Output is correct |
34 |
Correct |
11 ms |
8960 KB |
Output is correct |
35 |
Correct |
11 ms |
8960 KB |
Output is correct |
36 |
Correct |
11 ms |
9088 KB |
Output is correct |
37 |
Correct |
11 ms |
8960 KB |
Output is correct |
38 |
Correct |
10 ms |
8960 KB |
Output is correct |
39 |
Correct |
308 ms |
14968 KB |
Output is correct |
40 |
Correct |
305 ms |
14968 KB |
Output is correct |
41 |
Correct |
292 ms |
14968 KB |
Output is correct |
42 |
Correct |
265 ms |
15144 KB |
Output is correct |
43 |
Correct |
168 ms |
14968 KB |
Output is correct |
44 |
Correct |
98 ms |
15096 KB |
Output is correct |
45 |
Correct |
241 ms |
18268 KB |
Output is correct |
46 |
Correct |
144 ms |
21240 KB |
Output is correct |
47 |
Correct |
356 ms |
21496 KB |
Output is correct |
48 |
Correct |
699 ms |
33400 KB |
Output is correct |
49 |
Correct |
666 ms |
32640 KB |
Output is correct |
50 |
Correct |
340 ms |
21496 KB |
Output is correct |
51 |
Correct |
337 ms |
21696 KB |
Output is correct |
52 |
Correct |
477 ms |
21484 KB |
Output is correct |
53 |
Correct |
441 ms |
20984 KB |
Output is correct |
54 |
Correct |
467 ms |
21116 KB |
Output is correct |
55 |
Correct |
24 ms |
9600 KB |
Output is correct |
56 |
Correct |
24 ms |
9600 KB |
Output is correct |
57 |
Correct |
128 ms |
15008 KB |
Output is correct |
58 |
Correct |
52 ms |
15344 KB |
Output is correct |
59 |
Correct |
147 ms |
21368 KB |
Output is correct |
60 |
Correct |
672 ms |
32820 KB |
Output is correct |
61 |
Correct |
358 ms |
21496 KB |
Output is correct |
62 |
Correct |
349 ms |
21496 KB |
Output is correct |
63 |
Correct |
493 ms |
21624 KB |
Output is correct |
64 |
Correct |
1025 ms |
21080 KB |
Output is correct |
65 |
Correct |
718 ms |
21240 KB |
Output is correct |
66 |
Correct |
725 ms |
30456 KB |
Output is correct |
67 |
Correct |
146 ms |
21612 KB |
Output is correct |
68 |
Correct |
499 ms |
21496 KB |
Output is correct |
69 |
Correct |
487 ms |
21624 KB |
Output is correct |
70 |
Correct |
471 ms |
21088 KB |
Output is correct |