結果

問題 No.1344 Typical Shortest Path Sum
ユーザー simansiman
提出日時 2022-02-20 17:44:30
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,219 bytes
コンパイル時間 4,669 ms
コンパイル使用メモリ 107,460 KB
実行使用メモリ 5,060 KB
最終ジャッジ日時 2023-09-11 21:06:36
合計ジャッジ時間 10,744 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;

struct Node {
  int u;
  ll cost;

  Node(int u = -1, ll cost = -1) {
    this->u = u;
    this->cost = cost;
  }

  bool operator>(const Node &n) const {
    return cost > n.cost;
  }
};

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

  vector<int> E[N + 1];
  vector<ll> C[N + 1];
  for (int i = 0; i < M; ++i) {
    int s, t;
    ll d;
    cin >> s >> t >> d;

    E[s].push_back(t);
    C[s].push_back(d);
  }

  for (int r = 1; r <= N; ++r) {
    priority_queue <Node, vector<Node>, greater<Node>> pque;
    pque.push(Node(r, 0));

    ll ans = 0;
    vector<bool> visited(N + 1, false);

    while (not pque.empty()) {
      Node node = pque.top();
      pque.pop();

      if (visited[node.u]) continue;
      visited[node.u] = true;
      ans += node.cost;

      for (int i = 0; i < E[node.u].size(); ++i) {
        int t = E[node.u][i];
        ll d = C[node.u][i];

        pque.push(Node(t, node.cost + d));
      }
    }

    cout << ans << endl;
  }

  return 0;
}
0