我只有一句话可以说,他妈的比了。老子写的Dijkstra 竟然比 Floyd都慢,我可以去死了。他奶奶个熊。
还是Floyd好又快有简单。
/*
ID: niepeng1
LANG: C++
TASK: comehome
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <ctype.h>
//#include <iostream.h>
#define Max1 53
#define Maxedge 10100
#define INF 10000000
FILE *in,*out;
int map[Max1][Max1];
int vexnum;
//void Dijkstra(int map[][Max1],bool vexcond[],bool edgecond[],int num)
int char2num(char c)
{
assert(isalpha(c));
if(isupper(c))
return c-'A';
else
return c-'a'+26;
}
int main()
{
char a,b;
int i,j,c,m,k;
in=fopen("comehome.in","r");
out=fopen("comehome.out","w");
for(i=0;i<Max1;i++)
for(j=0;j<Max1;j++)
map[i][j]=INF;//地图初始化
fscanf(in,"%d",&vexnum);
for(j=0,i=0;j<vexnum;j++){
while(1){
fscanf(in,"%c",&a);
if(isalpha(a)!=0) break;
}
while(1){ fscanf(in,"%c",&b); if(isalpha(b)!=0) break;}
fscanf(in, "%d/n",&c);
a=char2num(a);
b=char2num(b);
if( map[a][b] >c)
map[b][a]=map[a][b]=c;
}
for(k=0;k<52;k++)
for(i=0;i<52;i++){
for(j=0;j<52;j++)
if( map[i][j] > map[i][k] + map[k][j])
map[i][j] = map[i][k] + map[k][j];
}
m=INF;
a='#';
for(i=0;i<25;i++)
{
if( m > map[i][25] )
{
m=map[i][25];
a=i;
}
}
a=a+'A';
printf("%c %d/n", a, m);
fprintf(out, "%c %d/n", a, m);
fclose(in);
fclose(out);
return 0;
}