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>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
const ll inf = 1e14 + 10000;
const int mod = 1e9+7;
const int maxn = 1e5 + 12;
vt<pii> g[maxn];
void ope(vll &a, int st){
a[st] = 0;
priority_queue<pair<ll, int>, vt<pair<ll, int>>, greater<pair<ll, int>>> pq;
pq.push({0, st});
while(!pq.empty()){
pair<ll, int> nw = pq.top();
pq.pop();
if(a[nw.ss] != nw.ff)continue;
for(auto i : g[nw.ss]){
if(nw.ff + i.ss < a[i.ff]) {
a[i.ff] = nw.ff + i.ss;
pq.push({a[i.ff], i.ff});
}
}
}
}
void solve() {
int n, m, s, t, u, v;
cin >> n >> m >> s >> t >> u >> v;
for(int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
a--, b--;
g[a].pb({b, c});
g[b].pb({a, c});
}
s--, t--, u--, v--;
vll a(n, inf), c(n, inf), d(n, inf);
ope(a, s), ope(c, u), ope(d, v);
queue<tuple<int, ll, ll>> q;
q.push({t, c[t], d[t]});
ll ans = d[u];
while(!q.empty()){
tuple<int, ll, ll> nw = q.front();
ans = min(ans, get<1>(nw) + get<2>(nw));
q.pop();
for(auto i : g[get<0>(nw)]){
if(a[i.ff] + i.ss == a[get<0>(nw)]){
q.push({i.ff, min(get<1>(nw), c[i.ff]), min(get<2>(nw), d[i.ff])});
}
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int times = 1;
//cin >> times;
for(int i = 1; i <= times; i++) {
solve();
}
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... |