結果
問題 | No.160 最短経路のうち辞書順最小 |
ユーザー |
![]() |
提出日時 | 2015-03-02 00:53:29 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 832 bytes |
コンパイル時間 | 273 ms |
コンパイル使用メモリ | 39,484 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 00:53:08 |
合計ジャッジ時間 | 1,462 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 5 WA * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | scanf("%d%d%d%d",&n,&m,&s,&g); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:15:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | scanf("%d%d%d",&a,&b,&c); | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include<cstdio>#include<algorithm>#include<vector>using namespace std;int n,m,s,g;int mat[300][300];bool flag[300][300];int main(){scanf("%d%d%d%d",&n,&m,&s,&g);fill_n(*mat,300*300,1<<25);fill_n(*flag,300*300,false);for(int i=0;i<n;i++)mat[i][i]=0;while(m--){int a,b,c;scanf("%d%d%d",&a,&b,&c);mat[a][b]=mat[b][a]=c;flag[a][b]=flag[b][a]=true;}for(int k=0;k<n;k++){for(int i=0;i<n;i++){for(int j=0;j<n;j++){mat[i][j]=min(mat[i][j],mat[i][k]+mat[k][j]);}}}printf("%d",s);while(s!=g){for(int i=0;i<n;i++){if(mat[s][i]+mat[i][g]==mat[s][g]&&flag[s][i]){printf(" %d",s=i);break;}}}puts("");}