結果

問題 No.1812 Uribo Road
ユーザー 👑 potato167potato167
提出日時 2022-01-14 22:49:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 5,000 ms
コード長 2,813 bytes
コンパイル時間 2,640 ms
コンパイル使用メモリ 219,344 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-30 16:31:56
合計ジャッジ時間 4,433 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 7 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 4 ms
6,944 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 38 ms
6,940 KB
testcase_13 AC 17 ms
6,940 KB
testcase_14 AC 17 ms
6,944 KB
testcase_15 AC 28 ms
6,944 KB
testcase_16 AC 25 ms
6,944 KB
testcase_17 AC 72 ms
6,940 KB
testcase_18 AC 15 ms
6,940 KB
testcase_19 AC 86 ms
6,944 KB
testcase_20 AC 86 ms
6,940 KB
testcase_21 AC 67 ms
6,944 KB
testcase_22 AC 55 ms
6,940 KB
testcase_23 AC 4 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 10 ms
6,944 KB
testcase_26 AC 3 ms
6,944 KB
testcase_27 AC 12 ms
6,944 KB
testcase_28 AC 20 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 4 ms
6,940 KB
testcase_31 AC 44 ms
6,944 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 28 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=1167167167167167167;
const int INF=2100000000;
const ll mod=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}


using len_type=int;
struct edge{
    int to;
    len_type length;
};

len_type dijkstra_movement(edge e,int from,len_type t){
    return t+e.length;
}


vector<len_type> dijkstra(vector<vector<edge>> &G,int start,len_type inf){
    int M=G.size();
    assert(M>start&&start>=0);
    vector<len_type> seen(M,inf);
    seen[start]=0;
    priority_queue<pair<len_type,int>,vector<pair<len_type,int>>,greater<pair<len_type,int>>> pq;
    pq.push({0,start});
    while(!pq.empty()){
        len_type time;
        int ver;
        tie(time,ver)=pq.top();
        pq.pop();
        if(seen[ver]<time) continue;
        for(edge x:G[ver]){
            len_type T=dijkstra_movement(x,ver,time);
            if(T<seen[x.to]){
                pq.push({T,x.to});
                seen[x.to]=T;
            }
        }
    }
    return seen;
}

//  rainy ~ 雨に打たれて ~
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int N,M,K;
	cin>>N>>M>>K;
	vector<int> R(K);
	rep(i,K) cin>>R[i],R[i]--;
	vector<int> A(M),B(M),C(M);
	vector<vector<edge>> G(N);
	rep(i,M){
		cin>>A[i]>>B[i]>>C[i];
		A[i]--,B[i]--;
		G[A[i]].push_back({B[i],C[i]});
		G[B[i]].push_back({A[i],C[i]});
	}
	vector<vector<int>> seen(K*2);
	rep(i,K){
		seen[i*2]=dijkstra(G,A[R[i]],INF);
		seen[i*2+1]=dijkstra(G,B[R[i]],INF);
	}
	vector<vector<int>> dp((1<<K),vector<int>(K*2,INF));
	rep(i,K){
		dp[(1<<i)][i*2]=seen[i*2+1][0]+C[R[i]];
		dp[(1<<i)][i*2+1]=seen[i*2][0]+C[R[i]];
	}
	rep(i,(1<<K)){
		rep(j,K*2){
			if(dp[i][j]==INF) continue;
			rep(k,K){
				if(i&(1<<k)) continue;
				int tmp=i+(1<<k);
				chmin(dp[tmp][k*2],dp[i][j]+seen[j][B[R[k]]]+C[R[k]]);
				chmin(dp[tmp][k*2+1],dp[i][j]+seen[j][A[R[k]]]+C[R[k]]);
			}
		}
	}
	int ans=INF;
	rep(j,K*2){
		//cout<<dp[(1<<K)-1][j]<<" "<<seen[j][N-1]<<"\n";
		chmin(ans,dp[(1<<K)-1][j]+seen[j][N-1]);
	}
	cout<<ans<<"\n";
}

0