結果
問題 |
No.1344 Typical Shortest Path Sum
|
ユーザー |
![]() |
提出日時 | 2022-02-20 17:44:30 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,219 bytes |
コンパイル時間 | 2,957 ms |
コンパイル使用メモリ | 144,384 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-29 10:54:09 |
合計ジャッジ時間 | 5,200 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 52 WA * 25 |
ソースコード
#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; }