結果
問題 |
No.160 最短経路のうち辞書順最小
|
ユーザー |
![]() |
提出日時 | 2015-03-12 10:06:07 |
言語 | C90 (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 975 bytes |
コンパイル時間 | 655 ms |
コンパイル使用メモリ | 22,400 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-24 17:24:16 |
合計ジャッジ時間 | 7,174 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | WA * 3 OLE * 1 -- * 22 |
コンパイルメッセージ
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]=1; } 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]==0){ next++; } for(i=next+1;i<N;i++){ if(path[now*N+i]==1 && time[next*N+G]>time[i*N+G]){ next=i; } } now=next; } printf("%d\n",G); free(time); return 0; }