106182024-04-06 22:34:56111Nagysebességű vasútcpp17Wrong answer 30/100368ms147264 KiB
#include<bits/stdc++.h>
using namespace std;

#define int long long

#define INF (int)1e16

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N,M;
	cin>>N>>M;
	vector<vector<pair<int,int>>>g(N);
	vector<tuple<int,int,int>>e;
	for(int i=0;i<M;i++){
		int a,b,c;
		cin>>a>>b>>c;
		g[a].emplace_back(b,c);
		g[b].emplace_back(a,c);
		e.emplace_back(a,b,c);
		e.emplace_back(b,a,c);
	}
	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>q;
	vector<int>d0(N,INF),d1(N,INF),p(N,-1),v(N);
	d0[0]=0;
	q.emplace(0,0);
	while(!q.empty()){
		auto[d,i]=q.top();
		q.pop();
		if(d0[i]<d){
			continue;
		}
		for(auto[j,w]:g[i]){
			if(d0[i]+w<d0[j]){
				d0[j]=d0[i]+w;
				p[j]=i;
				q.emplace(d0[j],j);
			}
		}
	}
	for(int i=N-1;i>=0;i=p[i]){
		v[i]=1;
	}
	d1[N-1]=0;
	q.emplace(0,N-1);
	while(!q.empty()){
		auto[d,i]=q.top();
		q.pop();
		if(d1[i]<d){
			continue;
		}
		for(auto[j,w]:g[i]){
			if(d1[i]+w<d1[j]){
				d1[j]=d1[i]+w;
				q.emplace(d1[j],j);
			}
		}
	}
	int ans=INF-1;
	for(auto[a,b,c]:e){
		if(v[a]&&v[b]){
			continue;
		}
		int x=d0[N-1]-d0[a]-d1[b];
		if(x<=0){
			continue;
		}
		ans=min(ans,c-x+1);
	}
	cout<<(ans+1)%INF-1<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2044 KiB
subtask20/35
3Accepted4ms2932 KiB
4Accepted4ms3256 KiB
5Accepted4ms3128 KiB
6Accepted4ms3484 KiB
7Accepted4ms3524 KiB
8Wrong answer4ms3772 KiB
subtask330/30
9Accepted94ms35468 KiB
10Accepted93ms36916 KiB
11Accepted93ms38332 KiB
12Accepted94ms40028 KiB
13Accepted93ms41312 KiB
14Accepted93ms43164 KiB
subtask40/35
15Accepted349ms99156 KiB
16Accepted351ms105636 KiB
17Accepted354ms111968 KiB
18Accepted351ms118212 KiB
19Accepted363ms124252 KiB
20Accepted361ms130004 KiB
21Accepted361ms135676 KiB
22Accepted368ms141612 KiB
23Accepted363ms147264 KiB
24Wrong answer179ms116440 KiB
25Accepted93ms101832 KiB
26Accepted93ms103284 KiB
27Accepted94ms104872 KiB