This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
struct point{
int64_t u,pp,bb;
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int64_t n,m;cin>>n>>m;
int64_t S,T;cin>>S>>T;
--S;--T;
int64_t U,V;cin>>U>>V;
--U;--V;
vector<vector<pair<int64_t,int64_t>>>adj(n);
for (int64_t i = 0;i<m;++i){
int64_t x,y,z;cin>>x>>y>>z;
--x;--y;
adj[x].push_back({y,z});
adj[y].push_back({x,z});
}
const int64_t mxn = 1e18;
priority_queue<pair<int64_t,pair<int64_t,int64_t>>>q;
vector<vector<int64_t>>dist(n,vector<int64_t>(2,mxn));
q.push({0,{U,0}});
q.push({0,{V,1}});
dist[U][0] = 0;
dist[V][1] = 0;
while(!q.empty()){
auto u = q.top().second;
q.pop();
for (auto x:adj[u.first]){
if (dist[x.first][u.second] > dist[u.first][u.second] + x.second){
dist[x.first][u.second] = dist[u.first][u.second] + x.second;
q.push({-dist[x.first][u.second],{x.first,u.second}});
}
}
}
int64_t ans = dist[U][1];
vector<int64_t>dis(n,mxn);
priority_queue<pair<long long,long long>>qs;
qs.push({0,S});
dis[S] = 0;
while(!qs.empty()){
auto u = qs.top();
qs.pop();
if (-u.first > dis[u.second])continue;
for (auto x:adj[u.second]){
if (dis[x.first] > dis[u.second] + x.second){
dis[x.first] = dis[u.second] + x.second;
qs.push({-dis[x.first],x.first});
}
}
}
auto bfs = [&](){
queue<point>qq;
qq.push({S,dist[S][0],dist[S][1]});
while(!qq.empty()){
auto u = qq.front();
qq.pop();
if (u.u == T){
ans = min(ans,u.pp + u.bb);
continue;
}
for (auto x:adj[u.u]){
if (dis[x.first] == dis[u.u] + x.second){
qq.push({x.first,min(u.pp,dist[x.first][0]),min(u.bb,dist[x.first][1])});
}
}
}
};
bfs();
cout<<ans<<'\n';
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |