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 task "C"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<ll, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 1e5 + 2;
const ll INF = 1e18;
int n, m, S, T, U, V;
ll dp[N], ans;
vii g[N];
vl dS, dT, dU, dV;
void dij(int r, vl &d)
{
d.assign(n + 1, INF);
d[r] = 0;
priority_queue<ii, vii, greater<ii> > pq;
pq.push({0, r});
while (!pq.empty())
{
int u = pq.top().S;
ll du = pq.top().F;
pq.pop();
if (du != d[u]) continue;
for (ii v : g[u]) if (d[v.F] > du + v.S)
{
d[v.F] = du + v.S;
pq.push({d[v.F], v.F});
}
}
}
bool in[N];
void updDP1(int u)
{
in[u] = 1;
dp[u] = dV[u];
for (ii v : g[u]) if (!in[v.F] && dS[u] + v.S + dT[v.F] == dS[T])
{
updDP1(v.F);
dp[u] = min(dp[u], dp[v.F]);
}
ans = min(ans, dU[u] + dp[u]);
}
void updDP()
{
queue<int> q;
q.push(S);
in[S] = 1;
while (!q.empty())
{
int u = q.front();
q.pop();
dp[u] = min(dp[u], dV[u]);
ans = min(ans, dU[u] + dp[u]);
for (ii v : g[u]) if (dS[u] + v.S + dT[v.F] == dS[T])
{
dp[v.F] = min(dp[v.F], dp[u]);
if (!in[v.F]) q.push(v.F), in[v.F] = 1;
}
}
}
int main()
{
#ifdef HynDuf
freopen(task".in", "r", stdin);
//freopen(task".out", "w", stdout);
#else
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
cin >> n >> m >> S >> T >> U >> V;
rep(i, 1, m)
{
int u, v, w;
cin >> u >> v >> w;
g[u].eb(v, w);
g[v].eb(u, w);
}
dij(S, dS);
dij(T, dT);
dij(U, dU);
dij(V, dV);
ans = dU[V];
fill(dp + 1, dp + 1 + n, INF);
updDP();
fill(dp + 1, dp + 1 + n, INF);
fill(in + 1, in + 1 + n, 0);
updDP1(S);
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... |