結果

問題 No.1344 Typical Shortest Path Sum
ユーザー 👑 Nachia
提出日時 2021-01-16 13:12:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 548 bytes
コンパイル時間 2,548 ms
コンパイル使用メモリ 191,956 KB
最終ジャッジ日時 2025-01-17 21:45:07
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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--; D[u][v]=min(D[u][v],d); }
      |                            ~~~~~^~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#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;

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--; D[u][v]=min(D[u][v],d); }
  rep(i,N) rep(j,N) rep(k,N) D[j][k]=min(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;
}
0