結果

問題 No.1812 Uribo Road
ユーザー MasKoaTSMasKoaTS
提出日時 2021-12-29 21:13:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,941 bytes
コンパイル時間 1,311 ms
コンパイル使用メモリ 104,656 KB
実行使用メモリ 183,396 KB
最終ジャッジ日時 2024-04-15 03:05:12
合計ジャッジ時間 8,533 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 34 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 44 ms
6,944 KB
testcase_09 AC 105 ms
6,940 KB
testcase_10 AC 31 ms
6,940 KB
testcase_11 AC 16 ms
6,944 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 | }
      | ^

ソースコード

diff #

#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;
}
0