10618 | 2024-04-06 22:34:56 | 111 | Nagysebességű vasút | cpp17 | Wrong answer 30/100 | 368ms | 147264 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 3ms | 2044 KiB | ||||
subtask2 | 0/35 | ||||||
3 | Accepted | 4ms | 2932 KiB | ||||
4 | Accepted | 4ms | 3256 KiB | ||||
5 | Accepted | 4ms | 3128 KiB | ||||
6 | Accepted | 4ms | 3484 KiB | ||||
7 | Accepted | 4ms | 3524 KiB | ||||
8 | Wrong answer | 4ms | 3772 KiB | ||||
subtask3 | 30/30 | ||||||
9 | Accepted | 94ms | 35468 KiB | ||||
10 | Accepted | 93ms | 36916 KiB | ||||
11 | Accepted | 93ms | 38332 KiB | ||||
12 | Accepted | 94ms | 40028 KiB | ||||
13 | Accepted | 93ms | 41312 KiB | ||||
14 | Accepted | 93ms | 43164 KiB | ||||
subtask4 | 0/35 | ||||||
15 | Accepted | 349ms | 99156 KiB | ||||
16 | Accepted | 351ms | 105636 KiB | ||||
17 | Accepted | 354ms | 111968 KiB | ||||
18 | Accepted | 351ms | 118212 KiB | ||||
19 | Accepted | 363ms | 124252 KiB | ||||
20 | Accepted | 361ms | 130004 KiB | ||||
21 | Accepted | 361ms | 135676 KiB | ||||
22 | Accepted | 368ms | 141612 KiB | ||||
23 | Accepted | 363ms | 147264 KiB | ||||
24 | Wrong answer | 179ms | 116440 KiB | ||||
25 | Accepted | 93ms | 101832 KiB | ||||
26 | Accepted | 93ms | 103284 KiB | ||||
27 | Accepted | 94ms | 104872 KiB |