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;
typedef long long ll;
#define FOR(i,a,b) for (int i = a; i <= b; ++i)
#define FORd(i,a,b) for (int i = a;i >= b; --i)
#define pii pair<ll,ll>
#define FastRead ios_base::sync_with_stdio(0); cin.tie(nullptr);
const int N = 2e5 + 10;
const ll oo = 1e18;
const int MOD = 1e9 + 7;
vector <pii> g[N + 10];
ll n,m,s,t,u,v,ans = oo;
ll vs[N + 10],dp[2][N + 10],du[N + 10],dv[N + 10],ds[N + 10];
void dijsktra1(int x, ll arr[])
{
memset(vs,false,sizeof(vs));
priority_queue <pii> pq;
pq.push({0,x});
while (!pq.empty()) {
ll c,node;
tie(c,node) = pq.top();
pq.pop();
if (!vs[node]) {
vs[node] = true;
arr[node] = -c;
for (pii i : g[node]) pq.push(pii(c - i.first,i.second));
}
}
}
void dijsktra2(ll x, ll y)
{
fill(dp[0], dp[0] + N, oo);
fill(dp[1], dp[1] + N, oo);
memset(vs,false,sizeof(vs));
priority_queue <pair <ll,pair <ll,ll>>> pq;
pq.push(make_pair(0ll,pii(x,0ll)));
while (!pq.empty()) {
ll c,node,par; pii p;
tie(c,p) = pq.top();
tie(node,par) = p;
pq.pop();
if (!vs[node]) {
vs[node] = true;
ds[node] = -c;
dp[0][node] = min(du[node], dp[0][par]);
dp[1][node] = min(dv[node], dp[1][par]);
for (pii i : g[node]) pq.push(make_pair(c - i.first,pii(i.second,node)));
}
else if (-c == ds[node]) {
ll so = min(du[node],dp[0][par]), so2 = min(dv[node],dp[1][par]);
if (so + so2 <= dp[0][node] + dp[1][node]) {
dp[0][node] = min({du[node], dp[0][par]});
dp[1][node] = min({dv[node], dp[1][par]});
}
}
}
ans = min(ans,dp[0][y] + dp[1][y]);
}
int main()
{
FastRead
cin >> n >> m >> s >> t >> u >> v;
FOR(i,1,m) {
int u,v,w;
cin >> u >> v >> w;
g[u].push_back(pii(w,v));
g[v].push_back(pii(w,u));
}
dijsktra1(u,du);
dijsktra1(v,dv);
ans = du[v];
dijsktra2(s,t);
dijsktra2(t,s);
cout << ans;
}
# | 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... |