結果
問題 | No.1812 Uribo Road |
ユーザー |
![]() |
提出日時 | 2021-12-29 21:13:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,941 bytes |
コンパイル時間 | 1,404 ms |
コンパイル使用メモリ | 100,704 KB |
最終ジャッジ日時 | 2025-01-27 07:31:04 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 TLE * 9 MLE * 1 |
コンパイルメッセージ
main.cpp: In function ‘int get_rnum(int, VV<int>&, V<int>&, int, int)’: main.cpp:26:1: warning: control reaches end of non-void function [-Wreturn-type] 26 | } | ^ main.cpp: In function ‘int dijkstra(int, int, VV<int>&, V<int>&, VV<std::pair<int, int> >&)’: main.cpp:63:1: warning: control reaches end of non-void function [-Wreturn-type] 63 | } | ^
ソースコード
#include <iostream>#include <vector>#include <queue>#include <set>#include <algorithm>#define rep(i, l, n) for (int i = (l); i < (n); i++)#define all(x) x.begin(), x.end()using namespace std;using Pair = pair<int, int>;template <class T>using V = vector<T>;template <class T>using VV = V<V<T> >;const int inf = 2000000000;int get_rnum(int K, VV<int>&edge, V<int>&R, int s, int t) {rep(i, 0, K) {if (s == edge[R[i]][0] and t == edge[R[i]][1]) {return i;}else if (s == edge[R[i]][1] and t == edge[R[i]][0]) {return i;}}}int dijkstra(int N, int K, VV<int>&edge, V<int>&R, VV<Pair>&route) {VV<int> dist(N, V<int>(1 << K, inf));set<V<int> > st = {};for (auto& i : R) {st.insert({ edge[i][0],edge[i][1] });st.insert({ edge[i][1],edge[i][0] });}priority_queue<V<int>, V<V<int> >, greater<V<int> > > pq;pq.push({ 0,0,0 });while (pq.size()) {V<int> p = pq.top(); pq.pop();int d = p[0]; int v = p[1]; int l = p[2];//cout << d << ' ' << v << ' ' << l << endl;if (v == N - 1 and l == (1 << K) - 1) {return d;}if (dist[v][l] == inf) {dist[v][l] = d;for (auto& r : route[v]) {int nv = r.first; int nd = r.second;if (st.find({ v,nv }) == st.end()) {if (dist[nv][l] == inf) {pq.push({ d + nd,nv,l });}}else {int nl = l | (1 << get_rnum(K, edge, R, v, nv));if (dist[nv][nl] == inf) {pq.push({ d + nd,nv,nl });}}}}}}int main(void) {int N, M, K; cin >> N >> M >> K;V<int> R(K);rep(i, 0, K) {cin >> R[i]; R[i] -= 1;}VV<int> edge(M, V<int>(3));VV<Pair> route(N, V<Pair>(0));rep(i, 0, M) {rep(j, 0, 3) {cin >> edge[i][j];}edge[i][0] -= 1; edge[i][1] -= 1;route[edge[i][0]].push_back({ edge[i][1],edge[i][2] });route[edge[i][1]].push_back({ edge[i][0],edge[i][2] });}int ans = dijkstra(N, K, edge, R, route);cout << ans << endl;return 0;}