結果
| 問題 |
No.1344 Typical Shortest Path Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-23 11:22:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,006 bytes |
| コンパイル時間 | 2,089 ms |
| コンパイル使用メモリ | 198,640 KB |
| 最終ジャッジ日時 | 2025-01-18 07:22:37 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 77 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n,m; cin >> n >> m;
vector<vector<ll>> d(n,vector<ll>(n,1e18));
for(int i=0;i<n;i++){
d[i][i]=0;
}
for(int i=0;i<m;i++){
int x,y; cin >> x >> y;
x--;y--;
ll w; cin >> w;
d[x][y]=min(d[x][y],w);
}
for(int k=0;k<n;k++){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(d[i][k]!=1e18 and d[k][j]!=1e18){
d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}
}
}
}
ll res=0;
for(int i=0;i<n;i++){
ll res=0;
for(int j=0;j<n;j++){
if(d[i][j]==1e18)d[i][j]=0;
res+=d[i][j];
}
cout << res << endl;
}
}