# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
171441 |
2019-12-28T16:34:59 Z |
nafis_shifat |
Race (IOI11_race) |
C++14 |
|
982 ms |
45808 KB |
#include "race.h"
#include<bits/stdc++.h>
#define pii pair<int,int>
#define ll long long
using namespace std;
const int mxn=2e5+9;
const int mexa=1e6+10;
vector<int> tree[mxn];
vector<int> cost[mxn];
int subsz[mxn];
int centroidMarked[mxn]={};
int parent[mxn]={};
int ans=mxn;
int K;
int cnt[mexa];
vector<int> csts;
void dfs(int cur,int prev)
{
subsz[cur]=1;
for(int i:tree[cur])
{
if(i!=prev && !centroidMarked[i])
{
dfs(i,cur);
subsz[cur]+=subsz[i];
}
}
}
int getCentroid(int cur,int prev,int sz)
{
bool isC=true;
int hc=-1;
for(int i:tree[cur])
{
if(i!=prev && !centroidMarked[i] && subsz[i]>sz)
{
hc=i;
isC=false;
break;
}
}
if(isC && subsz[cur]>=sz)return cur;
return getCentroid(hc,cur,sz);
}
int getCentroid(int src)
{
dfs(src,-1);
int c=getCentroid(src,-1,subsz[src]/2);
centroidMarked[c]=1;
return c;
}
void pans(int cur,int prev,int dst,int d)
{
if(dst>K)return;
ans=min(ans,d+cnt[K-dst]);
// cout<<K-dst<<" hehe "<<cur<<endl;
for(int i=0;i<tree[cur].size();i++)
{
int v=tree[cur][i];
if(!centroidMarked[v] && v!=prev)
{
pans(v,cur,dst+cost[cur][i],d+1);
}
}
}
void update(int cur,int prev,int dst,int d)
{
if(dst>K)return;
cnt[dst]=min(d,cnt[dst]);
csts.push_back(dst);
for(int i=0;i<tree[cur].size();i++)
{
int v=tree[cur][i];
if(!centroidMarked[v] && v!=prev)
{
update(v,cur,dst+cost[cur][i],d+1);
}
}
}
void df(int root)
{
int c=getCentroid(root);
//cout<<c<<endl;
for(int i:csts)cnt[i]=mxn;
csts.clear();
cnt[0]=0;
for(int i=0;i<tree[c].size();i++)
{
int v=tree[c][i];
if(!centroidMarked[v])
{
pans(v,c,cost[c][i],1);
update(v,c,cost[c][i],1);
}
}
for(int i:tree[c])
{
if(!centroidMarked[i])df(i);
}
}
int best_path(int N, int k, int H[][2], int L[])
{
for(int i=0;i<mexa;i++)cnt[i]=mxn;
K=k;
for(int i=0;i<N-1;i++)
{
tree[H[i][0]].push_back(H[i][1]);
tree[H[i][1]].push_back(H[i][0]);
cost[H[i][0]].push_back(L[i]);
cost[H[i][1]].push_back(L[i]);
}
df(0);
return ans==mxn?-1:ans;
}
Compilation message
race.cpp: In function 'void pans(int, int, int, int)':
race.cpp:74:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<tree[cur].size();i++)
~^~~~~~~~~~~~~~~~~
race.cpp: In function 'void update(int, int, int, int)':
race.cpp:90:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<tree[cur].size();i++)
~^~~~~~~~~~~~~~~~~
race.cpp: In function 'void df(int)':
race.cpp:111:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<tree[c].size();i++)
~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
13688 KB |
Output is correct |
2 |
Correct |
16 ms |
13688 KB |
Output is correct |
3 |
Correct |
15 ms |
13892 KB |
Output is correct |
4 |
Correct |
28 ms |
13560 KB |
Output is correct |
5 |
Correct |
15 ms |
13816 KB |
Output is correct |
6 |
Correct |
15 ms |
13688 KB |
Output is correct |
7 |
Correct |
15 ms |
13596 KB |
Output is correct |
8 |
Correct |
15 ms |
13688 KB |
Output is correct |
9 |
Correct |
15 ms |
13688 KB |
Output is correct |
10 |
Correct |
15 ms |
13688 KB |
Output is correct |
11 |
Correct |
15 ms |
13688 KB |
Output is correct |
12 |
Correct |
15 ms |
13764 KB |
Output is correct |
13 |
Correct |
15 ms |
13688 KB |
Output is correct |
14 |
Correct |
15 ms |
13688 KB |
Output is correct |
15 |
Correct |
15 ms |
13688 KB |
Output is correct |
16 |
Correct |
14 ms |
13660 KB |
Output is correct |
17 |
Correct |
15 ms |
13688 KB |
Output is correct |
18 |
Correct |
14 ms |
13688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
13688 KB |
Output is correct |
2 |
Correct |
16 ms |
13688 KB |
Output is correct |
3 |
Correct |
15 ms |
13892 KB |
Output is correct |
4 |
Correct |
28 ms |
13560 KB |
Output is correct |
5 |
Correct |
15 ms |
13816 KB |
Output is correct |
6 |
Correct |
15 ms |
13688 KB |
Output is correct |
7 |
Correct |
15 ms |
13596 KB |
Output is correct |
8 |
Correct |
15 ms |
13688 KB |
Output is correct |
9 |
Correct |
15 ms |
13688 KB |
Output is correct |
10 |
Correct |
15 ms |
13688 KB |
Output is correct |
11 |
Correct |
15 ms |
13688 KB |
Output is correct |
12 |
Correct |
15 ms |
13764 KB |
Output is correct |
13 |
Correct |
15 ms |
13688 KB |
Output is correct |
14 |
Correct |
15 ms |
13688 KB |
Output is correct |
15 |
Correct |
15 ms |
13688 KB |
Output is correct |
16 |
Correct |
14 ms |
13660 KB |
Output is correct |
17 |
Correct |
15 ms |
13688 KB |
Output is correct |
18 |
Correct |
14 ms |
13688 KB |
Output is correct |
19 |
Correct |
17 ms |
13688 KB |
Output is correct |
20 |
Correct |
18 ms |
13816 KB |
Output is correct |
21 |
Correct |
16 ms |
13688 KB |
Output is correct |
22 |
Correct |
16 ms |
13688 KB |
Output is correct |
23 |
Correct |
15 ms |
13688 KB |
Output is correct |
24 |
Correct |
15 ms |
13816 KB |
Output is correct |
25 |
Correct |
15 ms |
13688 KB |
Output is correct |
26 |
Correct |
15 ms |
13688 KB |
Output is correct |
27 |
Correct |
15 ms |
13688 KB |
Output is correct |
28 |
Correct |
16 ms |
13688 KB |
Output is correct |
29 |
Correct |
16 ms |
13688 KB |
Output is correct |
30 |
Correct |
16 ms |
13688 KB |
Output is correct |
31 |
Correct |
16 ms |
13688 KB |
Output is correct |
32 |
Correct |
16 ms |
13816 KB |
Output is correct |
33 |
Correct |
16 ms |
13816 KB |
Output is correct |
34 |
Correct |
16 ms |
13816 KB |
Output is correct |
35 |
Correct |
16 ms |
13688 KB |
Output is correct |
36 |
Correct |
16 ms |
13688 KB |
Output is correct |
37 |
Correct |
15 ms |
13816 KB |
Output is correct |
38 |
Correct |
19 ms |
13688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
13688 KB |
Output is correct |
2 |
Correct |
16 ms |
13688 KB |
Output is correct |
3 |
Correct |
15 ms |
13892 KB |
Output is correct |
4 |
Correct |
28 ms |
13560 KB |
Output is correct |
5 |
Correct |
15 ms |
13816 KB |
Output is correct |
6 |
Correct |
15 ms |
13688 KB |
Output is correct |
7 |
Correct |
15 ms |
13596 KB |
Output is correct |
8 |
Correct |
15 ms |
13688 KB |
Output is correct |
9 |
Correct |
15 ms |
13688 KB |
Output is correct |
10 |
Correct |
15 ms |
13688 KB |
Output is correct |
11 |
Correct |
15 ms |
13688 KB |
Output is correct |
12 |
Correct |
15 ms |
13764 KB |
Output is correct |
13 |
Correct |
15 ms |
13688 KB |
Output is correct |
14 |
Correct |
15 ms |
13688 KB |
Output is correct |
15 |
Correct |
15 ms |
13688 KB |
Output is correct |
16 |
Correct |
14 ms |
13660 KB |
Output is correct |
17 |
Correct |
15 ms |
13688 KB |
Output is correct |
18 |
Correct |
14 ms |
13688 KB |
Output is correct |
19 |
Correct |
289 ms |
23604 KB |
Output is correct |
20 |
Correct |
228 ms |
23416 KB |
Output is correct |
21 |
Correct |
245 ms |
23672 KB |
Output is correct |
22 |
Correct |
241 ms |
23920 KB |
Output is correct |
23 |
Correct |
177 ms |
23416 KB |
Output is correct |
24 |
Correct |
176 ms |
23720 KB |
Output is correct |
25 |
Correct |
273 ms |
26592 KB |
Output is correct |
26 |
Correct |
163 ms |
30060 KB |
Output is correct |
27 |
Correct |
392 ms |
34352 KB |
Output is correct |
28 |
Correct |
574 ms |
45688 KB |
Output is correct |
29 |
Correct |
618 ms |
44792 KB |
Output is correct |
30 |
Correct |
356 ms |
34424 KB |
Output is correct |
31 |
Correct |
346 ms |
34424 KB |
Output is correct |
32 |
Correct |
414 ms |
34424 KB |
Output is correct |
33 |
Correct |
485 ms |
33272 KB |
Output is correct |
34 |
Correct |
469 ms |
34052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
13688 KB |
Output is correct |
2 |
Correct |
16 ms |
13688 KB |
Output is correct |
3 |
Correct |
15 ms |
13892 KB |
Output is correct |
4 |
Correct |
28 ms |
13560 KB |
Output is correct |
5 |
Correct |
15 ms |
13816 KB |
Output is correct |
6 |
Correct |
15 ms |
13688 KB |
Output is correct |
7 |
Correct |
15 ms |
13596 KB |
Output is correct |
8 |
Correct |
15 ms |
13688 KB |
Output is correct |
9 |
Correct |
15 ms |
13688 KB |
Output is correct |
10 |
Correct |
15 ms |
13688 KB |
Output is correct |
11 |
Correct |
15 ms |
13688 KB |
Output is correct |
12 |
Correct |
15 ms |
13764 KB |
Output is correct |
13 |
Correct |
15 ms |
13688 KB |
Output is correct |
14 |
Correct |
15 ms |
13688 KB |
Output is correct |
15 |
Correct |
15 ms |
13688 KB |
Output is correct |
16 |
Correct |
14 ms |
13660 KB |
Output is correct |
17 |
Correct |
15 ms |
13688 KB |
Output is correct |
18 |
Correct |
14 ms |
13688 KB |
Output is correct |
19 |
Correct |
17 ms |
13688 KB |
Output is correct |
20 |
Correct |
18 ms |
13816 KB |
Output is correct |
21 |
Correct |
16 ms |
13688 KB |
Output is correct |
22 |
Correct |
16 ms |
13688 KB |
Output is correct |
23 |
Correct |
15 ms |
13688 KB |
Output is correct |
24 |
Correct |
15 ms |
13816 KB |
Output is correct |
25 |
Correct |
15 ms |
13688 KB |
Output is correct |
26 |
Correct |
15 ms |
13688 KB |
Output is correct |
27 |
Correct |
15 ms |
13688 KB |
Output is correct |
28 |
Correct |
16 ms |
13688 KB |
Output is correct |
29 |
Correct |
16 ms |
13688 KB |
Output is correct |
30 |
Correct |
16 ms |
13688 KB |
Output is correct |
31 |
Correct |
16 ms |
13688 KB |
Output is correct |
32 |
Correct |
16 ms |
13816 KB |
Output is correct |
33 |
Correct |
16 ms |
13816 KB |
Output is correct |
34 |
Correct |
16 ms |
13816 KB |
Output is correct |
35 |
Correct |
16 ms |
13688 KB |
Output is correct |
36 |
Correct |
16 ms |
13688 KB |
Output is correct |
37 |
Correct |
15 ms |
13816 KB |
Output is correct |
38 |
Correct |
19 ms |
13688 KB |
Output is correct |
39 |
Correct |
289 ms |
23604 KB |
Output is correct |
40 |
Correct |
228 ms |
23416 KB |
Output is correct |
41 |
Correct |
245 ms |
23672 KB |
Output is correct |
42 |
Correct |
241 ms |
23920 KB |
Output is correct |
43 |
Correct |
177 ms |
23416 KB |
Output is correct |
44 |
Correct |
176 ms |
23720 KB |
Output is correct |
45 |
Correct |
273 ms |
26592 KB |
Output is correct |
46 |
Correct |
163 ms |
30060 KB |
Output is correct |
47 |
Correct |
392 ms |
34352 KB |
Output is correct |
48 |
Correct |
574 ms |
45688 KB |
Output is correct |
49 |
Correct |
618 ms |
44792 KB |
Output is correct |
50 |
Correct |
356 ms |
34424 KB |
Output is correct |
51 |
Correct |
346 ms |
34424 KB |
Output is correct |
52 |
Correct |
414 ms |
34424 KB |
Output is correct |
53 |
Correct |
485 ms |
33272 KB |
Output is correct |
54 |
Correct |
469 ms |
34052 KB |
Output is correct |
55 |
Correct |
27 ms |
14684 KB |
Output is correct |
56 |
Correct |
28 ms |
14712 KB |
Output is correct |
57 |
Correct |
129 ms |
23776 KB |
Output is correct |
58 |
Correct |
63 ms |
24168 KB |
Output is correct |
59 |
Correct |
152 ms |
30084 KB |
Output is correct |
60 |
Correct |
982 ms |
45808 KB |
Output is correct |
61 |
Correct |
374 ms |
34680 KB |
Output is correct |
62 |
Correct |
455 ms |
35308 KB |
Output is correct |
63 |
Correct |
508 ms |
35188 KB |
Output is correct |
64 |
Correct |
844 ms |
34668 KB |
Output is correct |
65 |
Correct |
464 ms |
34512 KB |
Output is correct |
66 |
Correct |
794 ms |
42888 KB |
Output is correct |
67 |
Correct |
227 ms |
35892 KB |
Output is correct |
68 |
Correct |
476 ms |
35504 KB |
Output is correct |
69 |
Correct |
487 ms |
35776 KB |
Output is correct |
70 |
Correct |
440 ms |
34544 KB |
Output is correct |