結果
| 問題 |
No.1812 Uribo Road
|
| コンテスト | |
| ユーザー |
MasKoaTS
|
| 提出日時 | 2021-11-22 20:42:39 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,841 bytes |
| コンパイル時間 | 924 ms |
| コンパイル使用メモリ | 86,112 KB |
| 最終ジャッジ日時 | 2025-01-26 00:24:35 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 TLE * 1 |
| other | AC * 15 TLE * 15 |
ソースコード
// Warshall-Floyd
#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 = 1000000000;
void warshall_floyd(int N, VV<int>&dist) {
rep(i, 0, N) {
dist[i][i] = 0;
}
rep(k, 0, N) {
rep(i, 0, N) {
rep(j, 0, N) {
int d = dist[i][k] + dist[k][j];
if (dist[i][j] > d) {
dist[i][j] = d;
}
}
}
}
}
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<int> dist(N, V<int>(N, inf));
rep(i, 0, M) {
rep(j, 0, 3) {
cin >> edge[i][j];
}
edge[i][0] -= 1; edge[i][1] -= 1;
int a = edge[i][0]; int b = edge[i][1];
dist[a][b] = dist[b][a] = edge[i][2];
}
warshall_floyd(N, dist);
int ans = inf;
int rsum = 0;
rep(i, 0, R.size()) {
rsum += edge[R[i]][2];
}
rep(rbit, 0, 1 << K) {
V<int> b(K);
rep(i, 0, K) {
b[i] = (rbit >> i) & 1;
}
VV<int> dp(1 << K, V<int>(K, inf));
rep(i, 0, K) {
int p = edge[R[i]][b[i]];
dp[1 << i][i] = dist[0][p] + rsum;
}
rep(bit, 1, 1 << K) {
rep(s, 0, K) {
int p = edge[R[s]][b[s] ^ 1];
if (((bit >> s) & 1) == 0) {
continue;
}
rep(t, 0, K) {
int np = edge[R[t]][b[t]];
int k = bit | (1 << t);
int d = dp[bit][s] + dist[p][np];
if (((bit >> t) & 1) == 0 && dp[k][t] > d) {
dp[k][t] = d;
}
}
}
}
int c = inf;
rep(i, 0, K) {
int p = edge[R[i]][b[i] ^ 1];
int d = dp[(1 << K) - 1][i] + dist[p][N - 1];
if (c > d) {
c = d;
}
}
if (ans > c) {
ans = c;
}
}
cout << ans << endl;
return 0;
}
MasKoaTS