# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
123376 |
2019-07-01T09:08:29 Z |
baluteshih |
Race (IOI11_race) |
C++14 |
|
6 ms |
5116 KB |
#include "race.h"
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define F first
#define S second
#define MP make_pair
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
bitset<200005> vis;
vector<pll> G[200005];
const ll INF=1e9;
ll ans=INF,k,wei,w[200005],tmp[1000005];
void center(ll u,ll f,ll ¢,ll sz)
{
ll x=0;
w[u]=1;
for(pll i:G[u])
if(i.F!=f&&!vis[i.F])
center(i.F,u,cent,sz),x=max(x,w[i.F]),w[u]+=w[i.F];
x=max(x,sz-w[u]);
if(x<wei) wei=x,cent=u;
}
void dfs(ll u,ll f,ll d,ll r,vector<pll> &v)
{
v.pb(MP(d,r));
for(pll i:G[u])
if(i.F!=f&&!vis[i.F])
dfs(i.F,u,d+i.S,r+1,v);
}
void cut(ll u,ll sz)
{
ll c;
wei=INF,center(u,u,c,sz);
vis[c]=1;
for(pll i:G[c])
if(!vis[i.F])
if(w[i.F]>w[u]) cut(u,w[u]-w[c]);
else cut(i.F,w[i.F]);
vector<ll> rv;
for(pll i:G[c])
if(!vis[i.F])
{
vector<pll> v;
dfs(i.F,i.F,i.S,1,v);
for(pll j:v)
if(j.F<=k&&tmp[k-j.F]!=INF)
ans=min(ans,j.S+tmp[k-j.F]);
for(pll j:v)
if(j.F<=k)
if(tmp[j.F]==INF) tmp[j.F]=j.S,rv.pb(j.F);
else tmp[j.F]=min(tmp[j.F],j.S);
}
for(ll i:rv)
tmp[i]=INF;
vis[c]=0;
}
int best_path(int N, int K, int H[][2], int L[])
{
k=K,tmp[0]=0;
for(int i=1;i<=K;++i)
tmp[i]=INF;
for(int i=0;i<N-1;++i)
G[H[i][0]].pb(MP(H[i][1],L[i])),G[H[i][1]].pb(MP(H[i][0],L[i]));
cut(0,N);
if(ans==INF) return -1;
return ans;
}
Compilation message
race.cpp: In function 'void cut(ll, ll)':
race.cpp:47:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
if(!vis[i.F])
^
race.cpp:60:7: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
if(j.F<=k)
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
5116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
5116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
5116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
5116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |