답안 #133712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
133712 2019-07-21T08:53:04 Z tinjyu 경주 (Race) (IOI11_race) C++14
0 / 100
2 ms 508 KB
#include "race.h"
#include <iostream>
using namespace std;
int tag[200005],road[200005],map[400005][3],t[100000][2],n,k;
int a=10000000,ans[200005][205];
int find(int x)
{
	tag[x]=1;
	int g=road[x];
	//cout<<x<<endl;
	while(g!=-1)
	{
		int now=map[g][0];
		if(tag[now]!=1)
		{
			find(now);
			//cout<<x<<" "<<now<<endl;
			for(int i=map[g][2];i<=k;i++)
			{
				a=min(ans[now][i-map[g][2]]+ans[x][k-i]+1,a);
				//cout<<ans[now][i-map[g][2]]<<" "<<ans[x][k-i]<<" "<<k-i-map[g][2]<<"  ";
				
			}
			//cout<<endl;
			for(int i=0;i<=k-map[g][2];i++)ans[x][i+map[g][2]]=min(ans[now][i]+1,ans[x][i+map[g][2]]);
		}
		g=map[g][1];
	}
}
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]=10000000;
	}
	
	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;
	}
	if(k<100)
	{
		find(0);
		for(int i=0;i<n;i++)a=min(ans[i][k],a);
		if(a==10000000)a=-1;
  		return a;
  	}
  	else
  	{
  		for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)tag[j]=0;
		int p=0,pp=0;
		t[0][0]=i;
		t[0][1]=0;
		t[0][2]=0;
		tag[i]=1;
		while(p<=pp)
		{
			int x=t[p][0];
			int g=road[x];
			while(g!=-1)
			{
				int now=map[g][0];
				if(tag[now]==0)
				{
					tag[now]=1;
					pp++;
					t[pp][0]=now;
					t[pp][1]=t[p][1]+map[g][2];
					t[pp][2]=t[p][2]+1;
					if(t[pp][1]==k)
					{
						a=min(a,t[pp][2]);
						//cout<<now<<t<<endl;
					}
				}
				g=map[g][1];
			}
			p++;
		}
	}
	if(a==9999999)a=-1;
  	return a;
	}
}

Compilation message

race.cpp: In function 'int find(int)':
race.cpp:29:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:69:9: warning: array subscript is above array bounds [-Warray-bounds]
   t[0][2]=0;
   ~~~~~~^
race.cpp:84:21: warning: array subscript is above array bounds [-Warray-bounds]
      t[pp][2]=t[p][2]+1;
               ~~~~~~^
race.cpp:84:13: warning: array subscript is above array bounds [-Warray-bounds]
      t[pp][2]=t[p][2]+1;
      ~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Incorrect 2 ms 504 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Incorrect 2 ms 504 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Incorrect 2 ms 504 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Incorrect 2 ms 504 KB Output isn't correct
5 Halted 0 ms 0 KB -