# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
48996 |
2018-05-21T06:23:48 Z |
Namnamseo |
Race (IOI11_race) |
C++17 |
|
3000 ms |
46284 KB |
#include <bits/stdc++.h>
using namespace std;
#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define coord_comp(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define v_index(v, x) (lower_bound(all(v),x)-(v).begin())
typedef pair<int,int> pp;
typedef long long ll;
#include "race.h"
int n,k;
vector<pp> edge[200001];
bool dead[200010];
int nt;
int pre_time[200010];
int pre_par [200010];
int pre_size[200010];
int pre_mcsz[200010];
void pre_dfs(int x){
pre_size[x]=1;
pre_mcsz[x]=0;
pre_time[x]=nt;
for(pp ep : edge[x]){
int y = ep.first;
if(dead[y] || (pre_time[y]==nt && pre_par[x]==y)) continue;
pre_par[y]=x;
pre_dfs(y);
pre_mcsz[x] = max(pre_mcsz[x], pre_size[y]);
pre_size[x] += pre_size[y];
}
}
int find_cent(int root){
++nt;
pre_par[root] = -1;
pre_dfs(root);
int sz=pre_size[root];
while(true){
if(pre_mcsz[root] <= sz/2) break;
for(pp ep:edge[root]){
int y=ep.first;
if(dead[y] || pre_par[root]==y) continue;
if(pre_mcsz[root] == pre_size[y]){
root=y; break;
}
}
}
return root;
}
int ans=2e9;
int par[200010];
void dfs_child(int x, int depth, int dc, set<pp>& s){
s.insert({depth,dc});
for(pp ep:edge[x]){
int y=ep.first;
if(dead[y] || par[x]==y) continue;
par[y]=x;
dfs_child(y, depth+ep.second, dc+1, s);
}
}
inline void find_pairs(pp& t,multiset<pp>& s){
if(t.first > k) return;
auto it=s.lower_bound({k-t.first,0});
if(it!=s.end() && it -> first == k-t.first){
ans = min(ans, t.second + it->second);
}
}
void treat_root(int x){
vector<set<pp>> sets;
for(pp ep:edge[x]){
int y=ep.first;
if(dead[y]) continue;
par[y]=x;
set<pp> ns;
dfs_child(y, ep.second, 1, ns);
sets.pb(ns);
}
multiset<pp> s;
for(auto& ss:sets){
for(pp t:ss) s.insert(t);
}
s.insert({0,0});
for(auto& v:sets){
for(auto t:v) s.erase(s.find(t));
for(auto t:v) find_pairs(t, s);
for(auto t:v) s.insert(t);
}
}
int best_path(int N, int K, int H[][2], int L[]){
n=N; k=K;
for(int i=0; i<n-1; ++i){
edge[H[i][0]].emplace_back(H[i][1], L[i]);
edge[H[i][1]].emplace_back(H[i][0], L[i]);
}
queue<int> q;
q.push(1);
while(q.size()){
int t = q.front(); q.pop();
int cent = find_cent(t);
treat_root(cent);
dead[cent] = true;
for(pp ep:edge[cent]){
int y = ep.first;
if(!dead[y]){
q.push(y);
}
}
}
if(ans == int(2e9)) ans=-1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5116 KB |
Output is correct |
2 |
Correct |
7 ms |
5208 KB |
Output is correct |
3 |
Correct |
6 ms |
5208 KB |
Output is correct |
4 |
Correct |
8 ms |
5208 KB |
Output is correct |
5 |
Correct |
6 ms |
5208 KB |
Output is correct |
6 |
Correct |
6 ms |
5244 KB |
Output is correct |
7 |
Correct |
6 ms |
5384 KB |
Output is correct |
8 |
Correct |
6 ms |
5384 KB |
Output is correct |
9 |
Correct |
6 ms |
5384 KB |
Output is correct |
10 |
Correct |
8 ms |
5384 KB |
Output is correct |
11 |
Correct |
6 ms |
5480 KB |
Output is correct |
12 |
Correct |
8 ms |
5480 KB |
Output is correct |
13 |
Correct |
5 ms |
5480 KB |
Output is correct |
14 |
Correct |
5 ms |
5480 KB |
Output is correct |
15 |
Correct |
5 ms |
5480 KB |
Output is correct |
16 |
Correct |
6 ms |
5480 KB |
Output is correct |
17 |
Correct |
10 ms |
5480 KB |
Output is correct |
18 |
Correct |
6 ms |
5480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5116 KB |
Output is correct |
2 |
Correct |
7 ms |
5208 KB |
Output is correct |
3 |
Correct |
6 ms |
5208 KB |
Output is correct |
4 |
Correct |
8 ms |
5208 KB |
Output is correct |
5 |
Correct |
6 ms |
5208 KB |
Output is correct |
6 |
Correct |
6 ms |
5244 KB |
Output is correct |
7 |
Correct |
6 ms |
5384 KB |
Output is correct |
8 |
Correct |
6 ms |
5384 KB |
Output is correct |
9 |
Correct |
6 ms |
5384 KB |
Output is correct |
10 |
Correct |
8 ms |
5384 KB |
Output is correct |
11 |
Correct |
6 ms |
5480 KB |
Output is correct |
12 |
Correct |
8 ms |
5480 KB |
Output is correct |
13 |
Correct |
5 ms |
5480 KB |
Output is correct |
14 |
Correct |
5 ms |
5480 KB |
Output is correct |
15 |
Correct |
5 ms |
5480 KB |
Output is correct |
16 |
Correct |
6 ms |
5480 KB |
Output is correct |
17 |
Correct |
10 ms |
5480 KB |
Output is correct |
18 |
Correct |
6 ms |
5480 KB |
Output is correct |
19 |
Correct |
5 ms |
5480 KB |
Output is correct |
20 |
Correct |
7 ms |
5480 KB |
Output is correct |
21 |
Correct |
9 ms |
5500 KB |
Output is correct |
22 |
Correct |
11 ms |
5500 KB |
Output is correct |
23 |
Correct |
12 ms |
5500 KB |
Output is correct |
24 |
Correct |
9 ms |
5500 KB |
Output is correct |
25 |
Correct |
9 ms |
5500 KB |
Output is correct |
26 |
Correct |
10 ms |
5500 KB |
Output is correct |
27 |
Correct |
8 ms |
5500 KB |
Output is correct |
28 |
Correct |
12 ms |
5500 KB |
Output is correct |
29 |
Correct |
11 ms |
5500 KB |
Output is correct |
30 |
Correct |
9 ms |
5500 KB |
Output is correct |
31 |
Correct |
9 ms |
5500 KB |
Output is correct |
32 |
Correct |
10 ms |
5500 KB |
Output is correct |
33 |
Correct |
10 ms |
5500 KB |
Output is correct |
34 |
Correct |
9 ms |
5500 KB |
Output is correct |
35 |
Correct |
9 ms |
5500 KB |
Output is correct |
36 |
Correct |
9 ms |
5500 KB |
Output is correct |
37 |
Correct |
9 ms |
5620 KB |
Output is correct |
38 |
Correct |
9 ms |
5620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5116 KB |
Output is correct |
2 |
Correct |
7 ms |
5208 KB |
Output is correct |
3 |
Correct |
6 ms |
5208 KB |
Output is correct |
4 |
Correct |
8 ms |
5208 KB |
Output is correct |
5 |
Correct |
6 ms |
5208 KB |
Output is correct |
6 |
Correct |
6 ms |
5244 KB |
Output is correct |
7 |
Correct |
6 ms |
5384 KB |
Output is correct |
8 |
Correct |
6 ms |
5384 KB |
Output is correct |
9 |
Correct |
6 ms |
5384 KB |
Output is correct |
10 |
Correct |
8 ms |
5384 KB |
Output is correct |
11 |
Correct |
6 ms |
5480 KB |
Output is correct |
12 |
Correct |
8 ms |
5480 KB |
Output is correct |
13 |
Correct |
5 ms |
5480 KB |
Output is correct |
14 |
Correct |
5 ms |
5480 KB |
Output is correct |
15 |
Correct |
5 ms |
5480 KB |
Output is correct |
16 |
Correct |
6 ms |
5480 KB |
Output is correct |
17 |
Correct |
10 ms |
5480 KB |
Output is correct |
18 |
Correct |
6 ms |
5480 KB |
Output is correct |
19 |
Correct |
663 ms |
12796 KB |
Output is correct |
20 |
Correct |
769 ms |
12796 KB |
Output is correct |
21 |
Correct |
657 ms |
12796 KB |
Output is correct |
22 |
Correct |
709 ms |
12924 KB |
Output is correct |
23 |
Correct |
881 ms |
13308 KB |
Output is correct |
24 |
Correct |
420 ms |
13308 KB |
Output is correct |
25 |
Correct |
1340 ms |
25852 KB |
Output is correct |
26 |
Correct |
831 ms |
25852 KB |
Output is correct |
27 |
Correct |
1088 ms |
28768 KB |
Output is correct |
28 |
Execution timed out |
3043 ms |
46284 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5116 KB |
Output is correct |
2 |
Correct |
7 ms |
5208 KB |
Output is correct |
3 |
Correct |
6 ms |
5208 KB |
Output is correct |
4 |
Correct |
8 ms |
5208 KB |
Output is correct |
5 |
Correct |
6 ms |
5208 KB |
Output is correct |
6 |
Correct |
6 ms |
5244 KB |
Output is correct |
7 |
Correct |
6 ms |
5384 KB |
Output is correct |
8 |
Correct |
6 ms |
5384 KB |
Output is correct |
9 |
Correct |
6 ms |
5384 KB |
Output is correct |
10 |
Correct |
8 ms |
5384 KB |
Output is correct |
11 |
Correct |
6 ms |
5480 KB |
Output is correct |
12 |
Correct |
8 ms |
5480 KB |
Output is correct |
13 |
Correct |
5 ms |
5480 KB |
Output is correct |
14 |
Correct |
5 ms |
5480 KB |
Output is correct |
15 |
Correct |
5 ms |
5480 KB |
Output is correct |
16 |
Correct |
6 ms |
5480 KB |
Output is correct |
17 |
Correct |
10 ms |
5480 KB |
Output is correct |
18 |
Correct |
6 ms |
5480 KB |
Output is correct |
19 |
Correct |
5 ms |
5480 KB |
Output is correct |
20 |
Correct |
7 ms |
5480 KB |
Output is correct |
21 |
Correct |
9 ms |
5500 KB |
Output is correct |
22 |
Correct |
11 ms |
5500 KB |
Output is correct |
23 |
Correct |
12 ms |
5500 KB |
Output is correct |
24 |
Correct |
9 ms |
5500 KB |
Output is correct |
25 |
Correct |
9 ms |
5500 KB |
Output is correct |
26 |
Correct |
10 ms |
5500 KB |
Output is correct |
27 |
Correct |
8 ms |
5500 KB |
Output is correct |
28 |
Correct |
12 ms |
5500 KB |
Output is correct |
29 |
Correct |
11 ms |
5500 KB |
Output is correct |
30 |
Correct |
9 ms |
5500 KB |
Output is correct |
31 |
Correct |
9 ms |
5500 KB |
Output is correct |
32 |
Correct |
10 ms |
5500 KB |
Output is correct |
33 |
Correct |
10 ms |
5500 KB |
Output is correct |
34 |
Correct |
9 ms |
5500 KB |
Output is correct |
35 |
Correct |
9 ms |
5500 KB |
Output is correct |
36 |
Correct |
9 ms |
5500 KB |
Output is correct |
37 |
Correct |
9 ms |
5620 KB |
Output is correct |
38 |
Correct |
9 ms |
5620 KB |
Output is correct |
39 |
Correct |
663 ms |
12796 KB |
Output is correct |
40 |
Correct |
769 ms |
12796 KB |
Output is correct |
41 |
Correct |
657 ms |
12796 KB |
Output is correct |
42 |
Correct |
709 ms |
12924 KB |
Output is correct |
43 |
Correct |
881 ms |
13308 KB |
Output is correct |
44 |
Correct |
420 ms |
13308 KB |
Output is correct |
45 |
Correct |
1340 ms |
25852 KB |
Output is correct |
46 |
Correct |
831 ms |
25852 KB |
Output is correct |
47 |
Correct |
1088 ms |
28768 KB |
Output is correct |
48 |
Execution timed out |
3043 ms |
46284 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |