結果
問題 | No.1344 Typical Shortest Path Sum |
ユーザー |
👑 ![]() |
提出日時 | 2021-01-16 14:31:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 574 bytes |
コンパイル時間 | 1,807 ms |
コンパイル使用メモリ | 191,692 KB |
最終ジャッジ日時 | 2025-01-17 22:59:38 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 77 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:13:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | scanf("%d%d",&N,&M); | ~~~~~^~~~~~~~~~~~~~ main.cpp:16:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 16 | rep(i,M){ int u,v; LL d; scanf("%d%d%lld",&u,&v,&d); u--; v--; chmin(D[u][v],d); } | ~~~~~^~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>using namespace std;using LL=long long;using ULL=unsigned long long;#define rep(i,n) for(int i=0; i<(n); i++)const LL INF=1000000000000000000;void chmin(LL& l,LL r){ if(l>r) l=r; }int N,M;LL D[100][100];int main(){scanf("%d%d",&N,&M);rep(i,N) rep(j,N) D[i][j]=INF;rep(i,N) D[i][i]=0;rep(i,M){ int u,v; LL d; scanf("%d%d%lld",&u,&v,&d); u--; v--; chmin(D[u][v],d); }rep(i,N) rep(j,N) rep(k,N) chmin(D[j][k],D[j][i]+D[i][k]);rep(i,N){ LL ans=0; rep(j,N) if(D[i][j]<INF/2) ans+=D[i][j]; printf("%lld\n",ans); }return 0;}