結果
問題 |
No.160 最短経路のうち辞書順最小
|
ユーザー |
![]() |
提出日時 | 2015-03-12 10:12:49 |
言語 | C90 (gcc 12.3.0) |
結果 |
OLE
|
実行時間 | - |
コード長 | 885 bytes |
コンパイル時間 | 171 ms |
コンパイル使用メモリ | 22,400 KB |
実行使用メモリ | 1,536 KB |
最終ジャッジ日時 | 2024-06-12 05:12:04 |
合計ジャッジ時間 | 13,058 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | OLE * 1 -- * 3 |
other | -- * 26 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:9:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | scanf("%d %d %d %d",&N,&M,&S,&G); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.c:28:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 28 | scanf("%d %d %d",&a,&b,&c); | ^~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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*next]+time[next*N+G]!=time[now*N+G]){ next++; } now=next; } printf("%d\n",G); free(time); return 0; }