結果

問題 No.1812 Uribo Road
ユーザー 沙耶花沙耶花
提出日時 2022-01-14 22:14:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,788 bytes
コンパイル時間 4,057 ms
コンパイル使用メモリ 272,452 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-30 15:16:53
合計ジャッジ時間 9,407 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 45 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 RE -
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 5 ms
6,940 KB
testcase_08 RE -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 RE -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 RE -
testcase_18 RE -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 RE -
testcase_25 WA -
testcase_26 RE -
testcase_27 RE -
testcase_28 WA -
testcase_29 RE -
testcase_30 RE -
testcase_31 WA -
testcase_32 RE -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 2000000001
vector<int> a,b,c;
vector<int> get(vector<vector<int>> &E,int s){
	int N = E.size();
	vector<int> dis(N,Inf);
	
	dis[s] = 0;
	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> Q;
	Q.emplace(0,s);
	
	while(Q.size()>0){
		int D = Q.top().first;
		int u = Q.top().second;
		Q.pop();
		rep(i,E[u].size()){
			int ind = E[u][i];
			int v = u ^ a[ind] ^ b[ind];
			
			int DD = D + c[ind];
			if(dis[v] > DD){
				dis[v] = DD;
				Q.emplace(DD,v);
			}
		}
	}
	return dis;
}

int main(){
	
	int N,M,K;
	cin>>N>>M>>K;
	
	vector<int> R(K);
	rep(i,K){
		cin>>R[i];
		R[i]--;
	}
	
	a.resize(M),b.resize(M),c.resize(M);
	vector<vector<int>> E(N);
	rep(i,M){
		cin>>a[i]>>b[i]>>c[i];
		a[i]--;b[i]--;
		E[a[i]].push_back(i);
		E[b[i]].push_back(i);
	}
	
	vector<int> t;
	t.push_back(0);
	t.push_back(N-1);
	rep(i,K){
		t.push_back(a[R[i]]);
		t.push_back(b[R[i]]);
	}
	
	sort(t.begin(),t.end());
	t.erase(unique(t.begin(),t.end()),t.end());
	
	vector<vector<int>> ds(t.size());
	rep(i,t.size())ds[i] = get(E,t[i]);
	
	vector dp(t.size(),vector<int>(1<<K,Inf));
	dp[0][0] = 0;
	
	rep(i,3*K){
		vector ndp(t.size(),vector<int>(1<<K,Inf));
		rep(j,t.size()){
			rep(k,1<<K){
				
				rep(l,t.size()){
					ndp[l][k] = min(ndp[l][k],dp[j][k] + ds[j][l]);
				}
				rep(l,K){
					if(a[R[l]]==j){
						ndp[b[R[l]]][k|(1<<l)] = min(ndp[b[R[l]]][k|(1<<l)], dp[j][k] + c[R[l]]);
					}
					if(b[R[l]]==j){
						ndp[a[R[l]]][k|(1<<l)] = min(ndp[a[R[l]]][k|(1<<l)], dp[j][k] + c[R[l]]);
					}
				}
			}
		}
		swap(dp,ndp);
	}
	cout<<dp.back().back()<<endl;
	
	
	return 0;
}
0