結果
問題 |
No.1812 Uribo Road
|
ユーザー |
![]() |
提出日時 | 2022-01-20 04:42:43 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,676 bytes |
コンパイル時間 | 1,372 ms |
コンパイル使用メモリ | 146,032 KB |
実行使用メモリ | 575,076 KB |
最終ジャッジ日時 | 2024-11-23 14:17:29 |
合計ジャッジ時間 | 66,195 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 TLE * 9 MLE * 1 |
ソースコード
#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 Edge { int id; int u; ll cost; Edge(int id = -1, int u = -1, ll cost = -1) { this->id = id; this->u = u; this->cost = cost; } }; vector<Edge> E[10010]; struct Node { int v; int mask; ll cost; Node(int v = -1, int mask = -1, ll cost = -1) { this->v = v; this->mask = mask; this->cost = cost; } bool operator>(const Node &n) const { return cost > n.cost; } }; int main() { int N, M, K; cin >> N >> M >> K; vector<int> R(K); for (int i = 0; i < K; ++i) { cin >> R[i]; } for (int i = 1; i <= M; ++i) { int a, b; ll c; cin >> a >> b >> c; E[a].push_back(Edge(i, b, c)); E[b].push_back(Edge(i, a, c)); } priority_queue <Node, vector<Node>, greater<Node>> pque; pque.push(Node(1, 0, 0)); bool visited[2 << K][N + 1]; memset(visited, false, sizeof(visited)); ll ans = LLONG_MAX; while (not pque.empty()) { Node node = pque.top(); pque.pop(); if (visited[node.mask][node.v]) continue; visited[node.mask][node.v] = true; if (node.v == N && node.mask == (1 << K) - 1) { ans = min(ans, node.cost); continue; } for (Edge &e : E[node.v]) { int nmask = node.mask; for (int k = 0; k < K; ++k) { if (e.id != R[k]) continue; nmask |= (1 << k); } pque.push(Node(e.u, nmask, node.cost + e.cost)); } } cout << ans << endl; return 0; }