結果
| 問題 |
No.1812 Uribo Road
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-20 22:48:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,257 bytes |
| コンパイル時間 | 2,763 ms |
| コンパイル使用メモリ | 213,340 KB |
| 最終ジャッジ日時 | 2025-01-27 13:18:40 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 22 TLE * 7 MLE * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 60;
struct G{
int npos;
long long c;
int dbit;
};
struct HQ{
long long d;
int pos;
int bit;
bool operator<(const HQ& right) const{
return d > right.d;
}
};
int main(void){
int n, m, k;
cin >> n >> m >> k;
map<int, int> R;
int r;
for(int i = 0; i < k; i++){
cin >> r;
R[r - 1] = 1 << i;
}
vector<vector<G>> edges(n, vector<G>());
int a, b, c, d;
for(int i = 0; i < m; i++){
cin >> a >> b >> c;
a--; b--;
edges[a].push_back({b, c, R[i]});
edges[b].push_back({a, c, R[i]});
}
vector<vector<long long>> dist(n, vector<long long>(1 << k, inf));
dist[0][0] = 0;
priority_queue<HQ> hq;
hq.push({0, 0, 0});
while(!hq.empty()){
auto a = hq.top();
hq.pop();
if(a.d > dist[a.pos][a.bit]) continue;
for(auto b: edges[a.pos]){
int nbit = a.bit | b.dbit;
if(dist[b.npos][nbit] > b.c + a.d){
dist[b.npos][nbit] = b.c + a.d;
hq.push({b.c + a.d, b.npos, nbit});
}
}
}
cout << dist[n - 1][(1 << k) - 1] << "\n";
}