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 ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
const ll inf = 1e18 + 7;
ll n, m;
ll s, t;
ll u, v;
vector<pll> g[100009];
void dijk(ll beg, ll dis[], ll calctree, vector<ll> tree[]){
for(ll i = 1; i <= n; ++i)
dis[i] = inf;
dis[beg] = 0;
priority_queue<pll, vector<pll>, greater<pll>> pq;
pq.push({dis[beg], beg});
while(pq.size()){
ll v = pq.top().ss;
ll d = pq.top().ff;
pq.pop();
if(dis[v] < d) continue;
for(auto u : g[v]){
if(calctree && d+u.ss <= dis[u.ff])
tree[u.ff].pb(v);
if(d+u.ss < dis[u.ff]){
dis[u.ff] = d+u.ss;
pq.push({dis[u.ff], u.ff});
}
}
}
}
vector<ll> tree[100009];
ll diss[100009];
ll disu[100009];
ll disv[100009];
ll ans;
void dfs(ll v, ll minv, ll minu){
minv = min(minv, disv[v]);
minu = min(minu, disu[v]);
ans = min(ans, minv+minu);
for(auto u : tree[v])
dfs(u, minv, minu);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin >> n >> m;
cin >> s >> t;
cin >> u >> v;
while(m--){
ll x, y, z;
cin >> x >> y >> z;
g[x].pb({y, z});
g[y].pb({x, z});
}
dijk(s, diss, 1, tree);
dijk(u, disu, 0, tree);
dijk(v, disv, 0, tree);
ans = disu[v];
dfs(t, inf, inf);
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... |