城市问题

来源:互联网 发布:淘宝新规代购 编辑:程序博客网 时间:2024/05/04 21:40
  • 城市问题

    Time Limit:10000MS  Memory Limit:65536KTotal Submit:255 Accepted:95 Case Time Limit:1000MS

    Description

      设有n个城市,依次编号为0,1,2,……,n-1(n<=100),另外有一个文件保存n个城市之间的距离(每座城市之间的距离都小于等于1000)。当两城市之间的距离等于-1时,表示这两个城市没有直接连接。求指定城市k到每一个城市i(0<=I,k<=n-1)的最短距离。

    Input

    第一行有两个整数n和k,中间用空格隔开;以下是一个NxN的矩阵,表示城市间的距离,数据间用空格隔开。

    Output

    输出指定城市k到各城市间的距离(从第0座城市开始,中间用空格分开)

    Sample Input

    3 10 3 13 0 21 2 0

    Sample Output

    3 0 2

    Source

    elba


  • var  i,j,k,n,m:longint;  a:array[1..101,1..101]of longint;  x,y:array[1..101]of longint;begin  readln(n,m);  for i:=0 to n-1 do    for j:=0 to  n-1 do        read(a[i,j]);  for k:=0 to n-1 do    for i:=0 to n-1 do      for j:=0 to n-1 do        begin          if (a[k,i]+a[k,j]<a[i,j]) and (a[k,i]<>-1) and (a[k,j]<>-1) then           begin            a[i,j]:=a[k,i]+a[k,j];          end        end;  for i:=0 to n-1 do  write(a[n,i],' ')end.
0 0
原创粉丝点击