結果

問題 No.1344 Typical Shortest Path Sum
ユーザー rogi52rogi52
提出日時 2021-01-16 23:09:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 743 bytes
コンパイル時間 1,886 ms
コンパイル使用メモリ 172,416 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-28 11:06:06
合計ジャッジ時間 3,647 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 77
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    ll N,M; cin >> N >> M;
    vector<vector<ll>> dist(N, vector<ll> (N, 1e18));
    rep(i,M){
        int s,t; ll d;
        cin >> s >> t >> d;
        s--; t--;
        dist[s][t] = min(dist[s][t], d);
    }
    rep(i,N) dist[i][i] = 0;
    rep(k,N)rep(i,N)rep(j,N){
        if(dist[i][k] == 1e18 || dist[k][j] == 1e18) continue;
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }

    rep(i,N)rep(j,N) if(dist[i][j] == 1e18) dist[i][j] = 0;

    rep(i,N){
        ll ans = 0;
        rep(j,N) ans += dist[i][j];
        cout << ans << '\n';
    }
}
0