結果
問題 | No.807 umg tours |
ユーザー | siman |
提出日時 | 2021-05-20 13:12:03 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 696 ms / 4,000 ms |
コード長 | 1,642 bytes |
コンパイル時間 | 1,339 ms |
コンパイル使用メモリ | 141,072 KB |
実行使用メモリ | 31,532 KB |
最終ジャッジ日時 | 2024-04-18 14:02:36 |
合計ジャッジ時間 | 9,706 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
6,812 KB |
testcase_01 | AC | 4 ms
6,940 KB |
testcase_02 | AC | 3 ms
6,944 KB |
testcase_03 | AC | 4 ms
6,940 KB |
testcase_04 | AC | 4 ms
6,940 KB |
testcase_05 | AC | 3 ms
6,944 KB |
testcase_06 | AC | 4 ms
6,944 KB |
testcase_07 | AC | 3 ms
6,944 KB |
testcase_08 | AC | 3 ms
6,944 KB |
testcase_09 | AC | 4 ms
6,940 KB |
testcase_10 | AC | 4 ms
6,940 KB |
testcase_11 | AC | 445 ms
27,708 KB |
testcase_12 | AC | 377 ms
18,872 KB |
testcase_13 | AC | 533 ms
28,032 KB |
testcase_14 | AC | 238 ms
16,312 KB |
testcase_15 | AC | 188 ms
12,200 KB |
testcase_16 | AC | 592 ms
23,144 KB |
testcase_17 | AC | 696 ms
30,128 KB |
testcase_18 | AC | 690 ms
30,232 KB |
testcase_19 | AC | 672 ms
30,020 KB |
testcase_20 | AC | 364 ms
13,772 KB |
testcase_21 | AC | 405 ms
14,028 KB |
testcase_22 | AC | 147 ms
9,216 KB |
testcase_23 | AC | 123 ms
8,192 KB |
testcase_24 | AC | 354 ms
28,392 KB |
testcase_25 | AC | 665 ms
31,532 KB |
ソースコード
#include <cassert> #include <cmath> #include <algorithm> #include <iostream> #include <iomanip> #include <limits.h> #include <map> #include <queue> #include <set> #include <string.h> #include <vector> using namespace std; typedef long long ll; const int MAX_N = 100010; struct Edge { int to; ll cost; Edge(int to = -1, ll cost = -1) { this->to = to; this->cost = cost; } }; struct Node { int v; ll cost; bool use_ticket; Node(int v = -1, ll cost = -1, bool use_ticket = false) { this->v = v; this->cost = cost; this->use_ticket = use_ticket; } bool operator>(const Node &n) const { return cost > n.cost; } }; vector<Edge> E[MAX_N]; int main() { int N, M; cin >> N >> M; int a, b, c; for (int i = 0; i < M; ++i) { cin >> a >> b >> c; E[a].push_back(Edge(b, c)); E[b].push_back(Edge(a, c)); } priority_queue <Node, vector<Node>, greater<Node>> pque; pque.push(Node(1, 0)); ll costs[N + 1][2]; memset(costs, 0, sizeof(costs)); bool visited[N + 1][2]; memset(visited, false, sizeof(visited)); costs[1][1] = 0; visited[1][1] = true; while (not pque.empty()) { Node node = pque.top(); pque.pop(); if (visited[node.v][node.use_ticket]) continue; visited[node.v][node.use_ticket] = true; costs[node.v][node.use_ticket] = node.cost; for (auto &[u, cost] : E[node.v]) { pque.push(Node(u, node.cost + cost, node.use_ticket)); if (not node.use_ticket) { pque.push(Node(u, node.cost, true)); } } } for (int i = 1; i <= N; ++i) { cout << costs[i][0] + costs[i][1] << endl; } return 0; }