답안 #123372

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123372 2019-07-01T09:05:10 Z baluteshih 경주 (Race) (IOI11_race) C++14
0 / 100
6 ms 4984 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 &cent,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)
{
	if(d>k) return;
	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,c,i.S,1,v);
			for(pll j:v)
				if(tmp[k-j.F]!=INF)
					ans=min(ans,j.S+tmp[k-j.F]);
			for(pll j:v)
				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:48:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   if(!vis[i.F])
     ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 4984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 4984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 4984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 4984 KB Output isn't correct
2 Halted 0 ms 0 KB -