結果

問題 No.1814 Uribo Road (Easy)
ユーザー MasKoaTSMasKoaTS
提出日時 2021-10-24 12:14:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,831 bytes
コンパイル時間 1,392 ms
コンパイル使用メモリ 95,520 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-05-01 17:27:54
合計ジャッジ時間 10,883 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 6 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 319 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 24 ms
5,376 KB
testcase_13 AC 103 ms
5,376 KB
testcase_14 TLE -
testcase_15 AC 11 ms
5,376 KB
testcase_16 AC 196 ms
5,376 KB
testcase_17 AC 255 ms
5,376 KB
testcase_18 AC 92 ms
5,376 KB
testcase_19 AC 48 ms
5,376 KB
testcase_20 AC 63 ms
5,376 KB
testcase_21 AC 138 ms
5,376 KB
testcase_22 AC 169 ms
5,376 KB
testcase_23 AC 73 ms
5,376 KB
testcase_24 AC 959 ms
5,376 KB
testcase_25 AC 1,029 ms
5,376 KB
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#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 dijkstra(int n, int start, int finish, VV<Pair> &route) {
	V<int> path(n, -1);
	priority_queue<Pair, V<Pair>, greater<Pair> > pq;
	pq.push({ 0,start });
	while (pq.size()) {
		Pair p = pq.top();	pq.pop();
		int d = p.first;	int v = p.second;
		if (path[v] == -1) {
			path[v] = d;
			if (v == finish) {
				break;
			}
			rep(i, 0, route[v].size()) {
				Pair p = { d + route[v][i].second,route[v][i].first };
				pq.push(p);
			}
		}
	}
	return path[finish];
}


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;
	}
	sort(all(R));

	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 = inf;
	int rsum = 0;
	rep(i, 0, R.size()) {
		rsum += edge[R[i]][2];
	}
	VV<int> dist(N, V<int>(N));

	do {
		rep(bit, 0, 1 << K) {
			int s = rsum;
			V<int> path(1);
			rep(i, 0, K) {
				int b = (bit >> i) & 1;
				path.push_back(edge[R[i]][b]);
				path.push_back(edge[R[i]][b ^ 1]);
			}
			path.push_back(N - 1);
			for (int i = 0; i < path.size() - 1; i += 2) {
				dist[path[i]][path[i + 1]] = dist[path[i + 1]][path[i]] = dijkstra(N, path[i], path[i + 1], route);
				s += dist[path[i]][path[i + 1]];
			}
			if (ans > s) {
				ans = s;
			}
		}
	} while (next_permutation(all(R)));

	cout << ans << endl;
	return 0;
}
0