結果

問題 No.2805 Go to School
ユーザー highlighterhighlighter
提出日時 2024-07-04 17:14:50
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 397 ms / 2,000 ms
コード長 1,313 bytes
コンパイル時間 3,373 ms
コンパイル使用メモリ 261,988 KB
実行使用メモリ 34,316 KB
最終ジャッジ日時 2024-07-16 01:36:24
合計ジャッジ時間 10,146 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

vector<long long> dijkstra(vector<vector<pair<int,long long>>> G,int v){
	vector<bool> kakutei((int)(G.size()),false);
	vector<long long> cur((int)(G.size()),2000000000000LL);
	priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>> que;
	cur[v]=0;
	que.push(make_pair(cur[v],v));
	while(!que.empty()){
		int pos=que.top().second;
		que.pop();
		if(kakutei[pos]==true){
			continue;
		}
		kakutei[pos]=true;
		for(pair<int,int> i : G[pos]){
			int nex=i.first;
			long long cost=i.second;
			if(cur[nex]>cur[pos]+cost){
				cur[nex]=cur[pos]+cost;
				que.push(make_pair(cur[nex],nex));
			}
		}
	}
	return cur;
}

int main(){
	int N,M,L;
	long long S,E;
	cin >> N >> M >> L >> S >> E;
	vector<vector<pair<int,long long>>> G(N);
	for(int i=0;i<M;i++){
		int a,b;
		long long t;
		cin >> a >> b >> t;
		a--; b--;
		G[a].push_back(make_pair(b,t));
		G[b].push_back(make_pair(a,t));
	}
	vector<long long> dist1=dijkstra(G,0);
	vector<long long> dist2=dijkstra(G,N-1);
	long long ans=2000000000000LL;
	for(;L--;){
		int t;
		cin >> t;
		t--;
		long long d=dist1[t];
		if(d>=S+E){
			continue;
		}
		d=max(d,S);
		d+=dist2[t]+1;
		ans=min(ans,d);
	}
	if(ans==2000000000000){
		cout << -1 << endl;
		return 0;
	}
	cout << ans << endl;
}
0