結果

問題 No.1812 Uribo Road
ユーザー 👑 kmjpkmjp
提出日時 2022-01-14 23:18:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 5,000 ms
コード長 2,342 bytes
コンパイル時間 2,258 ms
コンパイル使用メモリ 210,768 KB
実行使用メモリ 5,568 KB
最終ジャッジ日時 2023-08-12 22:15:25
合計ジャッジ時間 4,848 ms
ジャッジサーバーID
(参考情報)
judge2 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 5 ms
4,428 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 38 ms
4,900 KB
testcase_13 AC 14 ms
4,984 KB
testcase_14 AC 15 ms
4,968 KB
testcase_15 AC 31 ms
4,624 KB
testcase_16 AC 26 ms
4,376 KB
testcase_17 AC 79 ms
5,160 KB
testcase_18 AC 14 ms
5,020 KB
testcase_19 AC 93 ms
5,500 KB
testcase_20 AC 94 ms
5,444 KB
testcase_21 AC 71 ms
5,500 KB
testcase_22 AC 53 ms
5,568 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 14 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 11 ms
4,568 KB
testcase_28 AC 25 ms
4,552 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 46 ms
5,084 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 30 ms
4,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
int M;
vector<pair<int,int>> E[10101];
int K;
int R[26];
int V[26];
ll dp[10101];
ll D[26][26];
int A[101010],B[101010],C[101010];

ll dp2[1<<12][12][2];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>K;
	FOR(i,K) {
		cin>>R[i];
		R[i]--;
	}
	FOR(i,M) {
		cin>>A[i]>>B[i]>>C[i];
		A[i]--;
		B[i]--;
		
		E[A[i]].push_back({B[i],C[i]});
		E[B[i]].push_back({A[i],C[i]});
	}
	FOR(i,K) {
		V[i*2]=A[R[i]];
		V[i*2+1]=B[R[i]];
	}
	V[2*K+1]=N-1;
	
	FOR(i,2*K+2) {
		FOR(j,N) dp[j]=1LL<<60;
		priority_queue<pair<ll,int>> Q;
		dp[V[i]]=0;
		Q.push({0,V[i]});
		while(Q.size()) {
			ll co=-Q.top().first;
			int cur=Q.top().second;
			Q.pop();
			if(dp[cur]!=co) continue;
			FORR2(e,c,E[cur]) if(dp[e]>co+c) {
				dp[e]=co+c;
				Q.push({-dp[e],e});
			}
		}
		FOR(j,2*K+2) D[i][j]=dp[V[j]];
	}
	
	
	FOR(i,K) {
		FOR(x,1<<K) dp2[x][i][0]=dp2[x][i][1]=1LL<<60;
	}
	
	FOR(i,K) {
		dp2[(1<<i)][i][0]=D[i*2+1][2*K]+C[R[i]];
		dp2[(1<<i)][i][1]=D[i*2][2*K]+C[R[i]];
	}
	
	int mask;
	FOR(mask,1<<K) {
		FOR(x,K) if(mask&(1<<x)) {
			FOR(y,K) if((mask&(1<<y))==0) {
				chmin(dp2[mask|(1<<y)][y][0],dp2[mask][x][0]+D[x*2][y*2+1]+C[R[y]]);
				chmin(dp2[mask|(1<<y)][y][1],dp2[mask][x][0]+D[x*2][y*2]+C[R[y]]);
				chmin(dp2[mask|(1<<y)][y][0],dp2[mask][x][1]+D[x*2+1][y*2+1]+C[R[y]]);
				chmin(dp2[mask|(1<<y)][y][1],dp2[mask][x][1]+D[x*2+1][y*2]+C[R[y]]);
				
			}
		}
	}
	ll mi=1LL<<60;
	FOR(x,K) {
		mi=min(mi,dp2[(1<<K)-1][x][0]+D[x*2][2*K+1]);
		mi=min(mi,dp2[(1<<K)-1][x][1]+D[x*2+1][2*K+1]);
	}
	cout<<mi<<endl;
	
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0