結果
| 問題 | No.1814 Uribo Road (Easy) |
| ユーザー |
siman
|
| 提出日時 | 2022-01-17 04:05:08 |
| 言語 | C++17(clang) (clang++ 22.1.2 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 242 ms / 2,000 ms |
| コード長 | 1,673 bytes |
| 記録 | |
| コンパイル時間 | 5,238 ms |
| コンパイル使用メモリ | 147,200 KB |
| 実行使用メモリ | 12,704 KB |
| 最終ジャッジ日時 | 2026-05-17 06:02:31 |
| 合計ジャッジ時間 | 9,701 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 44 |
コンパイルメッセージ
main.cpp:66:24: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
66 | bool visited[2 << K][N + 1];
| ^~~~~
main.cpp:66:24: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:47:7: note: declared here
47 | int N, M, K;
| ^
main.cpp:66:16: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
66 | bool visited[2 << K][N + 1];
| ^~~~~~
main.cpp:66:21: note: read of non-const variable 'K' is not allowed in a constant expression
66 | bool visited[2 << K][N + 1];
| ^
main.cpp:47:13: note: declared here
47 | int N, M, K;
| ^
2 warnings generated.
ソースコード
#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[210];
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;
}
siman