# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
126296 |
2019-07-07T11:26:30 Z |
ksmzzang2003 |
Race (IOI11_race) |
C++14 |
|
3000 ms |
18712 KB |
#include "race.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair <int,int> pii;
int N,K,L[200003];
int par[200003],sz[200003];
vector <pii> adj[200003];
int check[1000003];
bool del[200003];
int ans = 1987654321;
vector <pii> lazy;
vector <int> usecheck;
int dfs1(int now,int prev)
{
sz[now] =0;
bool reaf=true;
for(int i=0;i<adj[now].size();i++)
{
int next = adj[now][i].first;
int cost = adj[now][i].second;
if(next == prev) continue;
if(del[next]) continue;
reaf = false;
sz[now] += dfs1(next,now);
}
return ++sz[now];
}
int find_cen(int now,int prev)
{
for(int i=0;i<adj[now].size();i++)
{
int next = adj[now][i].first;
int cost = adj[now][i].second;
if(next == prev) continue;
if(del[next]) continue;
if(sz[next]*2>sz[now]) return find_cen(next,now);
}
return now;
}
int dfs2(int now,int prev,int sum,int depth)
{
int ret = 1987654321;
if(sum>K) return 1987654321;
if(check[K-sum]!=1987654321) ret= min(ret,depth + check[K-sum]);
lazy.push_back(pii(sum,depth));
for(int i=0;i<adj[now].size();i++)
{
int next = adj[now][i].first;
int cost = adj[now][i].second;
if(next == prev) continue;
if(del[next]) continue;
ret = min(ret,dfs2(next,now,sum+cost,depth+1));
if(sum==0)
{
while(!lazy.empty())
{
pii it = lazy.back(); lazy.pop_back();
check[it.first] = min(check[it.first],it.second),usecheck.push_back(it.first);
}
}
}
return ret;
}
void g(int now,int prev)
{
dfs1(now,-1);
int cen = find_cen(now,-1);
while(!usecheck.empty())
{
int it = usecheck.back(); usecheck.pop_back();
check[it]=1987654321;
}
check[0] = 0;
ans = min(ans,dfs2(cen,-1,0,0));
del[cen] = true;
for(int i=0;i<adj[cen].size();i++)
{
int next = adj[cen][i].first;
int cost = adj[cen][i].second;
if(del[next]) continue;
g(next,now);
}
}
int best_path(int n, int k, int h[][2], int l[])
{
fill(check,check+1000003,1987654321);
N= n ; K = k;
for(int i=0;i<n-1;i++)
{
adj[h[i][0]].push_back(pii(h[i][1],l[i]));
adj[h[i][1]].push_back(pii(h[i][0],l[i]));
}
g(1,-1);
return (ans>=1987654300)?-1:ans;
}
Compilation message
race.cpp: In function 'int dfs1(int, int)':
race.cpp:17:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<adj[now].size();i++)
~^~~~~~~~~~~~~~~~
race.cpp:20:13: warning: unused variable 'cost' [-Wunused-variable]
int cost = adj[now][i].second;
^~~~
race.cpp:16:10: warning: variable 'reaf' set but not used [-Wunused-but-set-variable]
bool reaf=true;
^~~~
race.cpp: In function 'int find_cen(int, int)':
race.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<adj[now].size();i++)
~^~~~~~~~~~~~~~~~
race.cpp:34:13: warning: unused variable 'cost' [-Wunused-variable]
int cost = adj[now][i].second;
^~~~
race.cpp: In function 'int dfs2(int, int, int, int)':
race.cpp:48:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<adj[now].size();i++)
~^~~~~~~~~~~~~~~~
race.cpp: In function 'void g(int, int)':
race.cpp:79:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<adj[cen].size();i++)
~^~~~~~~~~~~~~~~~
race.cpp:82:13: warning: unused variable 'cost' [-Wunused-variable]
int cost = adj[cen][i].second;
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8952 KB |
Output is correct |
2 |
Correct |
10 ms |
8952 KB |
Output is correct |
3 |
Correct |
10 ms |
8952 KB |
Output is correct |
4 |
Correct |
10 ms |
8952 KB |
Output is correct |
5 |
Correct |
10 ms |
8952 KB |
Output is correct |
6 |
Correct |
10 ms |
8956 KB |
Output is correct |
7 |
Correct |
10 ms |
8952 KB |
Output is correct |
8 |
Correct |
9 ms |
8952 KB |
Output is correct |
9 |
Correct |
10 ms |
8952 KB |
Output is correct |
10 |
Correct |
11 ms |
8952 KB |
Output is correct |
11 |
Correct |
10 ms |
8952 KB |
Output is correct |
12 |
Correct |
10 ms |
8972 KB |
Output is correct |
13 |
Correct |
10 ms |
8952 KB |
Output is correct |
14 |
Correct |
9 ms |
8952 KB |
Output is correct |
15 |
Correct |
9 ms |
8952 KB |
Output is correct |
16 |
Correct |
9 ms |
8952 KB |
Output is correct |
17 |
Correct |
9 ms |
8952 KB |
Output is correct |
18 |
Correct |
10 ms |
8952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8952 KB |
Output is correct |
2 |
Correct |
10 ms |
8952 KB |
Output is correct |
3 |
Correct |
10 ms |
8952 KB |
Output is correct |
4 |
Correct |
10 ms |
8952 KB |
Output is correct |
5 |
Correct |
10 ms |
8952 KB |
Output is correct |
6 |
Correct |
10 ms |
8956 KB |
Output is correct |
7 |
Correct |
10 ms |
8952 KB |
Output is correct |
8 |
Correct |
9 ms |
8952 KB |
Output is correct |
9 |
Correct |
10 ms |
8952 KB |
Output is correct |
10 |
Correct |
11 ms |
8952 KB |
Output is correct |
11 |
Correct |
10 ms |
8952 KB |
Output is correct |
12 |
Correct |
10 ms |
8972 KB |
Output is correct |
13 |
Correct |
10 ms |
8952 KB |
Output is correct |
14 |
Correct |
9 ms |
8952 KB |
Output is correct |
15 |
Correct |
9 ms |
8952 KB |
Output is correct |
16 |
Correct |
9 ms |
8952 KB |
Output is correct |
17 |
Correct |
9 ms |
8952 KB |
Output is correct |
18 |
Correct |
10 ms |
8952 KB |
Output is correct |
19 |
Correct |
10 ms |
8952 KB |
Output is correct |
20 |
Correct |
9 ms |
8952 KB |
Output is correct |
21 |
Correct |
10 ms |
9080 KB |
Output is correct |
22 |
Correct |
10 ms |
9080 KB |
Output is correct |
23 |
Correct |
12 ms |
9080 KB |
Output is correct |
24 |
Correct |
11 ms |
9052 KB |
Output is correct |
25 |
Correct |
10 ms |
9080 KB |
Output is correct |
26 |
Correct |
10 ms |
9080 KB |
Output is correct |
27 |
Correct |
10 ms |
8952 KB |
Output is correct |
28 |
Correct |
11 ms |
8992 KB |
Output is correct |
29 |
Correct |
10 ms |
9052 KB |
Output is correct |
30 |
Correct |
10 ms |
9080 KB |
Output is correct |
31 |
Correct |
11 ms |
9080 KB |
Output is correct |
32 |
Correct |
11 ms |
9080 KB |
Output is correct |
33 |
Correct |
11 ms |
9080 KB |
Output is correct |
34 |
Correct |
11 ms |
9080 KB |
Output is correct |
35 |
Correct |
12 ms |
9080 KB |
Output is correct |
36 |
Correct |
13 ms |
9080 KB |
Output is correct |
37 |
Correct |
14 ms |
9080 KB |
Output is correct |
38 |
Correct |
13 ms |
8952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8952 KB |
Output is correct |
2 |
Correct |
10 ms |
8952 KB |
Output is correct |
3 |
Correct |
10 ms |
8952 KB |
Output is correct |
4 |
Correct |
10 ms |
8952 KB |
Output is correct |
5 |
Correct |
10 ms |
8952 KB |
Output is correct |
6 |
Correct |
10 ms |
8956 KB |
Output is correct |
7 |
Correct |
10 ms |
8952 KB |
Output is correct |
8 |
Correct |
9 ms |
8952 KB |
Output is correct |
9 |
Correct |
10 ms |
8952 KB |
Output is correct |
10 |
Correct |
11 ms |
8952 KB |
Output is correct |
11 |
Correct |
10 ms |
8952 KB |
Output is correct |
12 |
Correct |
10 ms |
8972 KB |
Output is correct |
13 |
Correct |
10 ms |
8952 KB |
Output is correct |
14 |
Correct |
9 ms |
8952 KB |
Output is correct |
15 |
Correct |
9 ms |
8952 KB |
Output is correct |
16 |
Correct |
9 ms |
8952 KB |
Output is correct |
17 |
Correct |
9 ms |
8952 KB |
Output is correct |
18 |
Correct |
10 ms |
8952 KB |
Output is correct |
19 |
Correct |
286 ms |
14456 KB |
Output is correct |
20 |
Correct |
206 ms |
14492 KB |
Output is correct |
21 |
Correct |
217 ms |
14716 KB |
Output is correct |
22 |
Correct |
161 ms |
15156 KB |
Output is correct |
23 |
Correct |
115 ms |
14556 KB |
Output is correct |
24 |
Correct |
85 ms |
14396 KB |
Output is correct |
25 |
Execution timed out |
3032 ms |
18712 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8952 KB |
Output is correct |
2 |
Correct |
10 ms |
8952 KB |
Output is correct |
3 |
Correct |
10 ms |
8952 KB |
Output is correct |
4 |
Correct |
10 ms |
8952 KB |
Output is correct |
5 |
Correct |
10 ms |
8952 KB |
Output is correct |
6 |
Correct |
10 ms |
8956 KB |
Output is correct |
7 |
Correct |
10 ms |
8952 KB |
Output is correct |
8 |
Correct |
9 ms |
8952 KB |
Output is correct |
9 |
Correct |
10 ms |
8952 KB |
Output is correct |
10 |
Correct |
11 ms |
8952 KB |
Output is correct |
11 |
Correct |
10 ms |
8952 KB |
Output is correct |
12 |
Correct |
10 ms |
8972 KB |
Output is correct |
13 |
Correct |
10 ms |
8952 KB |
Output is correct |
14 |
Correct |
9 ms |
8952 KB |
Output is correct |
15 |
Correct |
9 ms |
8952 KB |
Output is correct |
16 |
Correct |
9 ms |
8952 KB |
Output is correct |
17 |
Correct |
9 ms |
8952 KB |
Output is correct |
18 |
Correct |
10 ms |
8952 KB |
Output is correct |
19 |
Correct |
10 ms |
8952 KB |
Output is correct |
20 |
Correct |
9 ms |
8952 KB |
Output is correct |
21 |
Correct |
10 ms |
9080 KB |
Output is correct |
22 |
Correct |
10 ms |
9080 KB |
Output is correct |
23 |
Correct |
12 ms |
9080 KB |
Output is correct |
24 |
Correct |
11 ms |
9052 KB |
Output is correct |
25 |
Correct |
10 ms |
9080 KB |
Output is correct |
26 |
Correct |
10 ms |
9080 KB |
Output is correct |
27 |
Correct |
10 ms |
8952 KB |
Output is correct |
28 |
Correct |
11 ms |
8992 KB |
Output is correct |
29 |
Correct |
10 ms |
9052 KB |
Output is correct |
30 |
Correct |
10 ms |
9080 KB |
Output is correct |
31 |
Correct |
11 ms |
9080 KB |
Output is correct |
32 |
Correct |
11 ms |
9080 KB |
Output is correct |
33 |
Correct |
11 ms |
9080 KB |
Output is correct |
34 |
Correct |
11 ms |
9080 KB |
Output is correct |
35 |
Correct |
12 ms |
9080 KB |
Output is correct |
36 |
Correct |
13 ms |
9080 KB |
Output is correct |
37 |
Correct |
14 ms |
9080 KB |
Output is correct |
38 |
Correct |
13 ms |
8952 KB |
Output is correct |
39 |
Correct |
286 ms |
14456 KB |
Output is correct |
40 |
Correct |
206 ms |
14492 KB |
Output is correct |
41 |
Correct |
217 ms |
14716 KB |
Output is correct |
42 |
Correct |
161 ms |
15156 KB |
Output is correct |
43 |
Correct |
115 ms |
14556 KB |
Output is correct |
44 |
Correct |
85 ms |
14396 KB |
Output is correct |
45 |
Execution timed out |
3032 ms |
18712 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |