C语言最短距离求救

来源:百度知道 编辑:UC知道 时间:2024/06/21 08:37:37
区域号 区域号 距离(m)
1 2 400
1 3 450
2 4 300
2 21 230
2 47 140
3 4 600
4 5 210
4 19 310
5 6 230
5 7 200
6 7 320
6 8 340
7 8 170
7 18 160
8 9 200
8 15 285
9 10 180
10 11 150
10 15 160
11 12 140
11 14 130
12 13 200
13 34 400
14 15 190
14 26 190
15 16 170
15 17 250
16 17 140
16 18 130
17 27 240
18 19 204
18 25 180
19 20 140
19 24 175
20 21 180
20 24 190
21 22 300
21 23 270
21 47 350
22 44 160
22 45 270
22 48 180
23 24 240
23 29 210
23 30 290
23 44 150
24 25 170
24 28 130
26 27 140
26 34 320
27 28 190
28 29 260
29 31 190
30 31 240
30 42 130
30 43 210
31 32 230
31 36 260
31 50 210
32 33 190
32 35 140
32 36 240
33 34 210
35 37 160
36 39 180
36 40 190
37 38 135
38 3

#include "stdio.h"
#include "stdlib.h"
struct node
{ int num;
struct node *next;
};

void main()
{int i,j,k,m,w=10000,n,s[100],dist[100];
int a[5][5]={10001,63, 95, 84, 10001,
63, 10001,49, 44, 37,
95, 49, 10001,10001,10001,
84, 44, 10001,10001,35,
10001,37, 10001,35, 10001};
struct node *path[100],*h,*p,*q,*p1,*p2;
printf ("please input n,i:\n");
scanf ("%d%d",&n,&i);

for (j=1;j<=n;j++)
{if (j==i) s[j]=1;
else s[j]=0;
dist[j]=a[i][j];
if(dist[j]<w&&j!=i)
{p2=(struct node *)malloc(sizeof(struct node));