답안 #132943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132943 2019-07-20T02:26:57 Z tinjyu 경주 (Race) (IOI11_race) C++14
0 / 100
2 ms 504 KB
#include "race.h"
#include <iostream>
using namespace std;
long long int p=0,a=9999999,tag[105],ans[10000][105],road[100005],map[200005][3],n,k;
int find(int x)
{
	p++;
	tag[x]=1;
	int g=road[x];
	//cout<<x<<endl;
	while(g!=-1)
	{
		int now=map[g][0];
		if(tag[now]!=1)
		{
			find(now);
			p--;
			//cout<<x<<" "<<now<<" "<<p<<endl;
			for(int i=0;i<=k-map[g][2];i++)
			{
				//cout<<ans[p][i]<<" ";
				if(ans[p+1][i]!=-1)
				{
					if(ans[p][i+map[g][2]]!=-1)ans[p][i+map[g][2]]=min(ans[p][i]+1,ans[p+1][i+map[g][2]]);
					else ans[p][i+map[g][2]]=ans[p+1][i]+1;
				}
				//cout<<ans[p][i+map[]]
			}
			//cout<<endl;
		}
		g=map[g][1];
	}
	if(ans[p][k]!=-1)a=min(a,ans[p][k]);
	//cout<<x<<" "<<p<<endl;
	//for(int i=0;i<=k;i++)cout<<ans[x][i]<<" ";
	//cout<<endl;
}
int best_path(int N, int K, int H[][2], int L[])
{
	n=N,k=K;
	for(int i=0;i<n;i++)
	{
		for(int j=1;j<=k;j++)ans[i][j]=-1;
	}
	for(int i=0;i<n;i++)road[i]=-1;
	for(int i=0;i<n-1;i++)
	{
		int x=H[i][0],y=H[i][1];
		map[i*2][0]=y;
		map[i*2][1]=road[x];
		map[i*2][2]=L[i];
		road[x]=i*2;
		map[i*2+1][0]=x;
		map[i*2+1][1]=road[y];
		map[i*2+1][2]=L[i];
		road[y]=i*2+1;
	}
	find(0);
	if(a==9999999)a=-1;
  	return a;
}

Compilation message

race.cpp: In function 'int find(int)':
race.cpp:37:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -