結果

問題 No.1812 Uribo Road
ユーザー 沙耶花沙耶花
提出日時 2022-01-14 22:17:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,057 ms / 5,000 ms
コード長 1,953 bytes
コンパイル時間 4,596 ms
コンパイル使用メモリ 271,696 KB
実行使用メモリ 6,068 KB
最終ジャッジ日時 2023-08-12 20:18:50
合計ジャッジ時間 9,108 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 56 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 5 ms
4,384 KB
testcase_09 AC 7 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 196 ms
5,636 KB
testcase_13 AC 164 ms
5,440 KB
testcase_14 AC 146 ms
5,196 KB
testcase_15 AC 43 ms
4,384 KB
testcase_16 AC 51 ms
4,640 KB
testcase_17 AC 146 ms
5,324 KB
testcase_18 AC 168 ms
4,376 KB
testcase_19 AC 257 ms
5,884 KB
testcase_20 AC 259 ms
5,980 KB
testcase_21 AC 238 ms
6,068 KB
testcase_22 AC 221 ms
5,932 KB
testcase_23 AC 24 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 20 ms
4,384 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 85 ms
4,380 KB
testcase_28 AC 33 ms
4,396 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 8 ms
4,384 KB
testcase_31 AC 208 ms
4,996 KB
testcase_32 AC 8 ms
4,380 KB
testcase_33 AC 1,057 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

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){
				if(dp[j][k]==Inf)continue;
				rep(l,t.size()){
					ndp[l][k] = min(ndp[l][k],dp[j][k] + ds[j][t[l]]);
				}
				rep(l,K){
					if(a[R[l]]==t[j]){
						int to = distance(t.begin(),lower_bound(t.begin(),t.end(),b[R[l]]));
						ndp[to][k|(1<<l)] = min(ndp[to][k|(1<<l)], dp[j][k] + c[R[l]]);
					}
					if(b[R[l]]==t[j]){
						int to = distance(t.begin(),lower_bound(t.begin(),t.end(),a[R[l]]));
						ndp[to][k|(1<<l)] = min(ndp[to][k|(1<<l)], dp[j][k] + c[R[l]]);
					}
				}
			}
		}
		swap(dp,ndp);
	}
	cout<<dp.back().back()<<endl;
	
	
	return 0;
}
0