結果

問題 No.1344 Typical Shortest Path Sum
ユーザー simansiman
提出日時 2022-02-20 18:04:30
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,120 bytes
コンパイル時間 1,493 ms
コンパイル使用メモリ 141,196 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-29 10:54:36
合計ジャッジ時間 3,449 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 74 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const ll INF = 1000000000000000;
ll dist[101][101];

void warshall_floyd(int v) {
  for (int k = 1; k <= v; k++) {
    for (int i = 1; i <= v; i++) {
      if (dist[i][k] == INF) continue;
      for (int j = 1; j <= v; j++) {
        if (dist[k][j] == INF) continue;

        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
}

int main() {
  int N, M;
  cin >> N >> M;

  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      dist[i][j] = INF;
    }

    dist[i][i] = 0;
  }

  for (int i = 0; i < M; ++i) {
    int s, t;
    ll d;
    cin >> s >> t >> d;

    dist[s][t] = d;
  }

  warshall_floyd(N);

  for (int s = 1; s <= N; ++s) {
    ll ans = 0;

    for (int t = 1; t <= N; ++t) {
      if (s == t) continue;
      if (dist[s][t] == INF) continue;

      ans += dist[s][t];
    }

    cout << ans << endl;
  }

  return 0;
}
0