結果
| 問題 |
No.1814 Uribo Road (Easy)
|
| ユーザー |
ゆにぽけ
|
| 提出日時 | 2023-10-18 00:08:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 2,000 ms |
| コード長 | 1,460 bytes |
| コンパイル時間 | 1,590 ms |
| コンパイル使用メモリ | 134,500 KB |
| 最終ジャッジ日時 | 2025-02-17 08:14:24 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 44 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<cmath>
#include<ctime>
#include<iomanip>
#include<numeric>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<random>
#include<atcoder/lazysegtree>
using namespace std;
int N,M,K,R[5];
vector<pair<int,pair<int,int>>> G[200];
long long dp[200][1 << 5];
void solve()
{
cin >> N >> M >> K;
for(int i = 0;i < K;i++) cin >> R[i],R[i]--;
sort(R,R+K);
int id = 0;
for(int i = 0;i < M;i++)
{
int u,v,w;
cin >> u >> v >> w;
u--; v--;
int x = 0;
if(id < K && R[id] == i) x |= 1 << id,id++;
G[u].push_back(make_pair(v,make_pair(w,x)));
G[v].push_back(make_pair(u,make_pair(w,x)));
}
assert(id == K);
for(int i = 0;i < N;i++)for(int j = 0;j < 1 << K;j++) dp[i][j] = (long long)1e18;
dp[0][0] = 0;
priority_queue<pair<long long,pair<int,int>>> Q;
Q.push(make_pair(-0,make_pair(0,0)));
while(!Q.empty())
{
long long cur = -Q.top().first;
auto [u,s] = Q.top().second;
Q.pop();
if(dp[u][s] < cur) continue;
for(auto [v,wx]:G[u])
{
int ns = s | wx.second;
if(dp[v][ns] > dp[u][s]+wx.first)
{
dp[v][ns] = dp[u][s]+wx.first;
Q.push(make_pair(-dp[v][ns],make_pair(v,ns)));
}
}
}
cout << dp[N-1][(1 << K)-1] << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1;
//cin >> tt;
while(tt--) solve();
}
ゆにぽけ