結果

問題 No.1344 Typical Shortest Path Sum
ユーザー CaliforniumerCaliforniumer
提出日時 2021-01-16 13:20:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,122 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 75,076 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-18 09:45:58
合計ジャッジ時間 11,062 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 WA -
testcase_06 WA -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 WA -
testcase_12 RE -
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 WA -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 WA -
testcase_26 RE -
testcase_27 WA -
testcase_28 RE -
testcase_29 WA -
testcase_30 RE -
testcase_31 RE -
testcase_32 WA -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 WA -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,380 KB
testcase_62 RE -
testcase_63 AC 2 ms
4,380 KB
testcase_64 AC 2 ms
4,376 KB
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 AC 2 ms
4,376 KB
testcase_69 AC 1 ms
4,384 KB
testcase_70 WA -
testcase_71 WA -
testcase_72 AC 2 ms
4,380 KB
testcase_73 AC 2 ms
4,376 KB
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;
Matrix d; // グラフの距離を格納した2次元配列(隣接行列)
          // d[u][v]は辺e=(u,v)のコスト(辺が存在しない場合はINF、ただしd[i][i]=0)

void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main() {
  int n, m;
  cin >> n;

  d = Matrix(n, vector<int>(n, INF));
  for (int i = 0; i < n; i++) d[i][i] = 0;
  
  cin >> m;
  for (int i = 0; i < m; i++) {
    int from, to, cost;
    cin >> from >> to >> cost;from--;to--;
    d[from][to] = min(d[from][to],cost);
  }
  
  warshall_floyd(n);
  for (int i = 0; i < n; i++) {
    int O=0;
    for (int j = 0; j < n; j++) {
      if (i != j && d[i][j] != INF)
        O+=d[i][j];//cout << i << "から" << j << "へのコスト: " << d[i][j] << endl;
    }
    cout<<O<<endl;
  }
}
0