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;
#define pii pair<int,int>
vector<pii> graph[100003];
int n,m,S,T,U,V,oo=1e9+1,min_dist;
int dist[4][100003];
bool vis[2][100003];
int wyn[2][100003];
void Dijkstra(int st, int par){
fill(dist[par],dist[par]+n+1,oo);
dist[par][st]=0;
priority_queue<pii,vector<pii>,greater<pii>> pq;
pq.push({0,st});
while(pq.size()){
auto [d,v]=pq.top();
pq.pop();
for (auto [u,w] : graph[v]){
if (d+w<dist[par][u]){
dist[par][u]=d+w;
pq.push({d+w,u});
}
}
}
}
int dfs(int v, int par){
if (vis[par][v])return wyn[par][v];
vis[par][v]=true;
wyn[par][v]=dist[par][v];
for (auto u : graph[v]){
if (dist[2][u.first]+u.second+dist[3][v]==min_dist || dist[3][u.first]+u.second+dist[2][v]==min_dist){
wyn[par][v]=min(wyn[par][v],dfs(u.first,par));
}
}
return wyn[par][v];
}
void init(){
cin >> n >> m >> S >> T >> U >> V;
int a,b,c;
for (int i = 1; i<=m; i++){
cin >> a >> b >> c;
graph[a].push_back({b,c});
graph[b].push_back({a,c});
}
Dijkstra(U,0);
Dijkstra(V,1);
Dijkstra(S,2);
Dijkstra(T,3);
min_dist=dist[2][T];
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
init();
int ans=dist[0][V];
for (int i = 1; i<=n; i++){
ans=min({ans,dfs(i,0)+dist[1][i],dfs(i,1)+dist[0][i]});
}
cout << ans << '\n';
}
# | 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... |