結果
問題 | No.1344 Typical Shortest Path Sum |
ユーザー | shiomusubi496 |
提出日時 | 2021-01-16 13:39:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 634 bytes |
コンパイル時間 | 1,531 ms |
コンパイル使用メモリ | 166,732 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-27 14:06:33 |
合計ジャッジ時間 | 3,437 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 77 |
ソースコード
#include<bits/stdc++.h> #define int long long using namespace std; const int INF=1e18; void chmin(int&a,int b){if(a>b)a=b;} int N,M,dist[110][110]; signed main(){ cin>>N>>M; fill(dist[0],dist[N],INF); for(int i=0;i<N;i++)dist[i][i]=0; for(int i=0;i<M;i++){ int a,b,c;cin>>a>>b>>c; chmin(dist[a-1][b-1],c); } for(int k=0;k<N;k++)for(int i=0;i<N;i++)for(int j=0;j<N;j++) if(dist[i][k]!=INF&&dist[k][j]!=INF)chmin(dist[i][j],dist[i][k]+dist[k][j]); for(int i=0;i<N;i++){ int sum=0; for(int j=0;j<N;j++)sum+=(dist[i][j]==INF?0:dist[i][j]); cout<<sum<<endl; } }