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;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 10000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define single_case solve();
#define line cerr<<"----------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); }
#define mod 1000000007LL
const int N = 2e5 + 5;
vector<pair<ll, ll> > g[N];
ll ds[N], dt[N], du[N], dv[N];
ll n, m, s, t, u, v;
int vidjen[N];
void dijkstra(ll src, ll dis[])
{
for(int i = 0;i<N;i++) dis[i] = LINF, vidjen[i] = 0;
priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > pq;
dis[src] = 0;
pq.push(make_pair(0, src));
while(len(pq))
{
ll u = pq.top().second;
pq.pop();
if(vidjen[u]) continue;
vidjen[u] = 1;
for(auto x : g[u])
{
ll v = x.first;
ll c = x.second;
if(dis[v]>dis[u]+c)
{
dis[v] = dis[u] + c;
pq.push(make_pair(dis[v], v));
}
}
}
}
void dijkstramod(ll src, ll dis[])
{
for(int i = 0;i<N;i++) dis[i] = LINF, vidjen[i] = 0;
priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > pq;
dis[src] = 0;
pq.push(make_pair(0, src));
while(len(pq))
{
ll u = pq.top().second;
pq.pop();
if(vidjen[u]) continue;
vidjen[u] = 1;
for(auto x : g[u])
{
ll v = x.first;
ll c = x.second;
ll k = 0;
if(ds[u]+c+dt[v]!=ds[v]) k = c;
if(dis[v]>dis[u]+k)
{
dis[v] = dis[u] + k;
pq.push(make_pair(dis[v], v));
}
}
}
}
int main()
{
ios
cin>>n>>m>>s>>t>>u>>v;
for(int i = 0;i<m;i++)
{
ll a, b, c;
cin>>a>>b>>c;
g[a].pb(make_pair(b, c));
g[b].pb(make_pair(a, c));
}
dijkstra(s, ds);
dijkstra(t, dt);
dijkstramod(u, du);
dijkstramod(v, dv);
ll res = LINF;
for(int i = 1;i<=n;i++)
{
res = min(res, du[i]+dv[i]);
}
cout<<res;
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... |