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 DEBUG 0
using namespace std;
const int N = 1e5 + 10;
const long long INF = 1e18 + 7;
vector <pair <int, int>> adj[N];
int n;
long long ans;
long long dist[4][N], dist2[N];
bool visited[4][N], visited2[N];
void Dijkstra(int id, int s) {
fill(dist[id], dist[id] + n + 1, INF);
priority_queue <pair <long long, int>> pq;
pq.emplace(0, s);
dist[id][s] = 0;
while(!pq.empty()) {
int u = pq.top().second;
pq.pop();
if(visited[id][u] == true) {
continue;
}
visited[id][u] = true;
for(auto [v, w] : adj[u]) {
if(visited[id][v] == false and dist[id][u] + w < dist[id][v]) {
dist[id][v] = dist[id][u] + w;
pq.emplace(-dist[id][v], v);
}
}
}
}
void dfs(int id, int u) {
dist2[u] = dist[3][u];
visited2[u] = true;
for(auto [v, w] : adj[u]) {
if(dist[id ^ 1][v] + w == dist[id ^ 1][u]) {
if(visited2[v] == false) {
dfs(id, v);
}
dist2[u] = min(dist2[u], dist2[v]);
}
}
ans = min(ans, dist2[u] + dist[2][u]);
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int m, S, T, U, V;
cin >> n >> m >> S >> T >> U >> V;
while(m--) {
int a, b, c;
cin >> a >> b >> c;
adj[a].emplace_back(b, c);
adj[b].emplace_back(a, c);
}
Dijkstra(0, S);
Dijkstra(1, T);
Dijkstra(2, U);
Dijkstra(3, V);
ans = dist[2][V];
dfs(0, S);
fill(visited2, visited2 + n + 1, false);
dfs(1, T);
cout << ans;
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... |