結果
| 問題 |
No.1344 Typical Shortest Path Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-16 13:20:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,122 bytes |
| コンパイル時間 | 683 ms |
| コンパイル使用メモリ | 74,400 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-27 13:35:26 |
| 合計ジャッジ時間 | 9,223 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 WA * 18 RE * 51 |
ソースコード
#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;
}
}