結果

問題 No.160 最短経路のうち辞書順最小
ユーザー akakimidoriakakimidori
提出日時 2015-03-12 10:13:52
言語 C90
(gcc 11.4.0)
結果
OLE  
実行時間 -
コード長 887 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 25,792 KB
実行使用メモリ 1,672 KB
最終ジャッジ日時 2023-09-02 22:58:41
合計ジャッジ時間 14,109 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 OLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>


int main(void){

  int N,M,S,G;

  scanf("%d %d %d %d",&N,&M,&S,&G);

  int *time,*path;
  time=(int *)malloc(sizeof(int)*N*N);
  path=(int *)malloc(sizeof(int)*N*N);

  int i,j,k;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      time[i*N+j]=(1<<30)/400;
      path[i*N+j]=0;
      if(i==j){
        time[i*N+j]=0;
      }
    }
  }

  for(i=0;i<M;i++){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    time[a*N+b]=c;
    path[a*N+b]=c;
  }

  for(k=0;k<N;k++){
    for(i=0;i<N;i++){
      for(j=0;j<N;j++){
        if(time[i*N+j]>time[i*N+k]+time[k*N+j]){
          time[i*N+k]=time[i*N+k]+time[k*N+j];
        }
      }
    }
  }

  int now=S;
  while(now!=G){
    printf("%d ",now);
    int next=0;
    while(path[now*N+next]+time[next*N+G]!=time[now*N+G]){
      next++;
    }
    now=next;
  }
  printf("%d\n",G);
  free(time);
  return 0;
}
0