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>
#define int long long
using namespace std;
int N, M, S, T, U, V;
vector<pair<int, int>> graph[100000];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
int dist[100000], dists[100000], distt[100000], distu[100000], distv[100000];
int dp[100000];
int ans = 1e9;
void dij(int start){
pq.push({0, start});
fill(dist, dist+N, 1e17);
dist[start] = 0;
while(!pq.empty()){
int id = pq.top().second, d = pq.top().first;
pq.pop();
if(dist[id] != d){
continue;
}
for(pair<int, int> i : graph[id]){
if(d + i.second < dist[i.first]){
dist[i.first] = d + i.second;
pq.push({dist[i.first], i.first});
}
}
}
}
int dfs(int id, int (&dar)[100000]){
if(~dp[id]) return dp[id];
//cout << id << endl;
dp[id] = distu[id];
for(pair<int, int> i : graph[id]){
if(dar[i.first] == dar[id] - i.second){
dp[id] = min(dp[id], dfs(i.first, dar));
}
}
ans = min(ans, dp[id] + distv[id]);
return dp[id];
}
int32_t main(){
cin >> N >> M >> S >> T >> U >> V;
S--, T--, U--, V--;
for(int i = 0; i < M; i++){
int a, b, c; cin >> a >> b >> c;
graph[a-1].push_back({b-1, c});
graph[b-1].push_back({a-1, c});
}
dij(S);
copy(dist, dist+N, dists);
dij(T);
copy(dist, dist+N, distt);
dij(U);
copy(dist, dist+N, distu);
dij(V);
copy(dist, dist+N, distv);
fill(dp, dp+N, -1);
dfs(T, dists);
fill(dp, dp+N, -1);
dfs(S, distt);
cout << ans << endl;
}
# | 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... |