# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
104357 |
2019-04-05T15:16:47 Z |
nvmdava |
Race (IOI11_race) |
C++17 |
|
7 ms |
4992 KB |
#include "race.h"
#include <bits/stdc++.h>
#define N 200005
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
using namespace std;
bool blocked[N];
int n, s;
vector<pii> adj[N];
int sz[N];
int sumsz;
int len[5 * N];
void get_size(int v, int p){
sz[v] = 1;
len[v] = 0x3f3f3f3f;
for(auto& c : adj[v]){
if(c.ff == p || blocked[c.ff])
continue;
get_size(c.ff, v);
sz[v] += sz[c.ff];
}
}
int get_centroid(int v, int p){
for(auto& c : adj[v]){
if(c.ff == p || blocked[c.ff])
continue;
if(sz[c.ff] >= sumsz / 2)
return get_centroid(c.ff, v);
}
return v;
}
int ans = N;
queue<pii> q;
void dfs(int v, int p, int l, int cnt){
ans = min(ans, len[s - l] + cnt);
q.push({l, cnt});
cnt++;
for(auto& c : adj[v]){
if(c.ff == p || blocked[c.ff])
continue;
dfs(c.ff, v, l + c.ss, cnt);
}
if(p == -1){
while(!q.empty()){
len[q.front().ff] = min(len[q.front().ff], q.front().ss);
q.pop();
}
}
}
void decomp(int v){
get_size(v, -1);
v = get_centroid(v, -1);
blocked[v] = 1;
for(auto &c : adj[v]){
if(blocked[c.ff])
continue;
dfs(c.ff, -1, 0, 0);
}
for(auto &c : adj[v]){
if(blocked[c.ff])
continue;
decomp(c.ff);
}
}
int best_path(int n, int s, int h[][2], int l[]){
::n = n;
::s = s;
for(int i = 0; i < n - 1; i++){
adj[h[i][0]].pb({h[i][1], l[i]});
adj[h[i][1]].pb({h[i][0], l[i]});
}
decomp(1);
return (ans == N ? -1 : ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
4992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
4992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
4992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
4992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |