# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
100397 |
2019-03-10T22:18:47 Z |
SuperJumbo |
Race (IOI11_race) |
C++14 |
|
2 ms |
384 KB |
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define NMAX 1001
#else
#define NMAX 200005
#endif
#define inf (INT_MAX>>2)
#define ll long long
#define add push_back
#define mp make_pair
#include "race.h"
using namespace std;
vector<vector<pair<int,int>>> g;
int tot, k, ans;
int sz[NMAX], cen[NMAX];
unordered_map<int,int> all,sub;
void dfs(int node,int par){
sz[node] = 1;
for(auto e:g[node]){
int x = e.first;
if(x == par || cen[x] )continue;
dfs(x,node);
sz[node] += sz[x];
}
tot = max(tot,sz[node]);
}
int centroid(int node,int par){
for(auto e:g[node]){
int x = e.first;
if(x!=par && sz[x]> tot/2 && !cen[x]){
return centroid(x,node);
}
}
cen[node] = 1;
return node;
}
void dfs2(int node, int par, int cc, int len){
if(len == k) ans = min(ans, cc);
if(len >= k) return;
if(all[k-len]) ans = min(ans,all[k-len]+cc);
if(!sub[len]) sub[len] = cc;
sub[len] = min(sub[len],cc);
for(auto e:g[node]){
int x = e.first;
if(!cen[x] && x != par)
dfs2(x,node,cc+1,len + e.second);
}
}
void dcmp(int node,int par){
tot = 0;
dfs(node,par);
int c = centroid(node,par);
all.clear();
for(auto e :g[c]){
int x = e.first;
if(cen[x])continue;
sub.clear();
dfs2(x,c,1,e.second);
for(auto u:sub)
all[u.first] = all[u.first] == 0 ? u.second : min(all[u.first],u.second);
}
for(auto e:g[c]){
int x = e.first;
if(!cen[x]) dcmp(x,c);
}
}
int best_path(int n,int K,int h[][2] ,int L[]) {
k = K;
g.resize(n);
for(int i = 0 ;i<n-1;i++){
int u = h[i][0], v = h[i][1];
g[u].add(mp(v,L[i]));g[v].add(mp(u,L[i]));
}
memset(cen,0,sizeof(cen));
ans = inf;
dcmp(0,-1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |