結果

問題 No.1812 Uribo Road
ユーザー 👑 potato167potato167
提出日時 2022-01-14 22:49:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 5,000 ms
コード長 2,813 bytes
コンパイル時間 2,515 ms
コンパイル使用メモリ 216,792 KB
実行使用メモリ 5,832 KB
最終ジャッジ日時 2023-08-12 21:26:45
合計ジャッジ時間 4,535 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 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 3 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 35 ms
5,200 KB
testcase_13 AC 16 ms
5,064 KB
testcase_14 AC 16 ms
5,200 KB
testcase_15 AC 26 ms
4,388 KB
testcase_16 AC 24 ms
4,604 KB
testcase_17 AC 70 ms
5,204 KB
testcase_18 AC 14 ms
4,388 KB
testcase_19 AC 85 ms
5,832 KB
testcase_20 AC 85 ms
5,716 KB
testcase_21 AC 65 ms
5,816 KB
testcase_22 AC 53 ms
5,464 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 10 ms
4,424 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 11 ms
4,380 KB
testcase_28 AC 19 ms
4,388 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 42 ms
4,456 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 26 ms
4,596 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