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 int64_t
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ar = array<int, 2>;
const int64_t INF = 1ll << 60;
const int N = 2e5 + 5;
int n, m, S, T, U, V, d[4][N], mnd;
vector<ar> adj[N];
bool mark[N], mark2[N];
void dfs(int v) {
mark[v] = true;
for (auto [u, w]: adj[v]) if (!w && !mark[u])
dfs(u);
mnd = min(mnd, d[2][v]);
}
void dfs2(int v) {
mark2[v] = true;
for (auto [u, w]: adj[v]) if (!w && !mark2[u])
dfs2(u);
d[2][v] = min(d[2][v], mnd);
}
void dij(int x, int d[]) {
fill(d, d + N, INF);
priority_queue<ar> q;
q.push({d[x] = 0, x});
while (q.size()) {
auto [di, v] = q.top();
q.pop();
if (-di > d[v]) continue;
for (auto [u, w]: adj[v]) {
w += d[v];
if (w < d[u]) {
d[u] = w;
q.push({-d[u], u});
}
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> S >> T >> U >> V;
--S, --T, --U, --V;
FOR(i, 0, m) {
int u, v, w;
cin >> u >> v >> w;
--u, --v;
adj[v].push_back({u, w});
adj[u].push_back({v, w});
}
dij(T, d[0]);
dij(S, d[1]);
dij(U, d[2]);
dij(V, d[3]);
FOR(v, 0, n) for (auto &[u, w]: adj[v])
w = w + d[0][v] + d[1][u] == d[0][S] ? 0 : w;
/*
FOR(i, 0, n) if (!mark[i]) {
mnd = INF;
dfs(i);
dfs2(i);
}
int mn = INF;
FOR(i, 0, n) mn = min(mn, d[2][i] + d[3][i]);
*/
dij(U, d[2]);
dij(V, d[3]);
cout << min(d[2][V], d[3][U]) << '\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... |