10619 | 2024-04-06 22:36:36 | 111 | Nagysebességű vasút | cpp17 | Accepted 100/100 | 361ms | 84432 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<=1){
continue;
}
ans=min(ans,c-x+1);
}
cout<<(ans+1)%INF-1<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 3ms | 2060 KiB | ||||
subtask2 | 35/35 | ||||||
3 | Accepted | 4ms | 2916 KiB | ||||
4 | Accepted | 4ms | 3228 KiB | ||||
5 | Accepted | 4ms | 3272 KiB | ||||
6 | Accepted | 4ms | 3704 KiB | ||||
7 | Accepted | 4ms | 3604 KiB | ||||
8 | Accepted | 4ms | 3716 KiB | ||||
subtask3 | 30/30 | ||||||
9 | Accepted | 92ms | 33864 KiB | ||||
10 | Accepted | 96ms | 33960 KiB | ||||
11 | Accepted | 92ms | 33900 KiB | ||||
12 | Accepted | 93ms | 33896 KiB | ||||
13 | Accepted | 93ms | 33920 KiB | ||||
14 | Accepted | 92ms | 33916 KiB | ||||
subtask4 | 35/35 | ||||||
15 | Accepted | 345ms | 84192 KiB | ||||
16 | Accepted | 344ms | 84196 KiB | ||||
17 | Accepted | 344ms | 84344 KiB | ||||
18 | Accepted | 349ms | 84332 KiB | ||||
19 | Accepted | 354ms | 84432 KiB | ||||
20 | Accepted | 356ms | 84156 KiB | ||||
21 | Accepted | 361ms | 84132 KiB | ||||
22 | Accepted | 358ms | 84288 KiB | ||||
23 | Accepted | 360ms | 84144 KiB | ||||
24 | Accepted | 174ms | 50204 KiB | ||||
25 | Accepted | 92ms | 34096 KiB | ||||
26 | Accepted | 93ms | 34112 KiB | ||||
27 | Accepted | 90ms | 34100 KiB |