| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么会runtime error啊,实在看不出来什么错,不得已贴个代码,哪位大大帮忙看看/*pku 2394*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 505
#define MAX 70005
int t[N][N];
int f,p,c,m;
int find[N],need[N],out[N];
void init()0/*初始化*/
{
int ii,jj;
memset(find,0,sizeof(find));
for(ii=1;ii<=f;ii++)
for(jj=1;jj<=f;jj++)
t[ii][jj]=MAX;
}
void dijk()
{
int min,ii,jj,begin;
for(ii=1;ii<=f;ii++)
need[ii]=t[1][ii];
find[1]=1;need[1]=0;
for(ii=1;ii<=f;ii++)
{
min=MAX;
for(jj=2;jj<=f;jj++)
if(!find[jj]&&need[jj]<min)
{
min=need[jj];
begin=jj;
}
find[begin]=1;
if(min>m)
break;
for(jj=2;jj<=f;jj++)
if(min+t[begin][jj]<need[jj])
need[jj]=min+t[begin][jj];
}
}
int main()
{
int ii,jj;
int a,b,temp,ans;
while(scanf("%d%d%d%d",&f,&p,&c,&m)!=EOF)
{
init();
for(ii=1;ii<=p;ii++)
{
scanf("%d%d%d",&a,&b,&temp);
if(temp<t[a][b]&&a<=f&&b<=f)
t[a][b]=t[b][a]=temp;
}
dijk();
for(ii=1,jj=0;ii<=c;ii++)
{
scanf("%d",&temp);
if(need[temp]<=m)
out[jj++]=ii;
}
ans=jj;
printf("%d\n",ans);
for(ii=0;ii<ans;ii++)
printf("%d\n",out[ii]);
}
return 1;
}
/*
7 6 5 8
1 4 2
1 2 1
2 3 6
3 5 5
5 4 6
1 7 9
1
4
5
3
7
*/
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator