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 fi first
#define se second
#define all(r) (r).begin(), (r).end()
#define MASK(i) (1 << (i))
#define BIT(x, i) ((x) >> (i) & 1)
#define ll long long
#define pb push_back
#define TASK "task"
using namespace std;
template <typename T1, typename T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false;}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;}
const int oo = 1e9 + 7;
const ll loo = (ll)1e18 + 7;
const int LOG = 18;
const int BASE = 323;
const int N = 1e5 + 7;
int n, m, s, t, u, v;
ll dist[N], dist2[N], revdist[N];
vector<pair<ll, ll> > g[N];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen(TASK".inp", "r", stdin);
// freopen(TASK".out", "w", stdout);
cin >> n >> m >> s >> t >> u >> v;
for (int i = 1; i <= m; i++){
int a, b, c; cin >> a >> b >> c;
g[a].pb({b, c});
g[b].pb({a, c});
}
for (int i = 1; i <= n; i++) {
dist[i] = loo;
dist2[i] = loo;
revdist[i] = loo;
}
dist[s] = 0;
priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll>> > kew;
kew.push({0, s});
while (!kew.empty()){
auto k = kew.top();
kew.pop();
if (dist[k.se] < k.fi) continue;
for (auto u : g[k.se]){
if (u.se + k.fi < dist[u.fi]){
dist[u.fi] = u.se + k.fi;
kew.push({dist[u.fi], u.fi});
}
}
}
revdist[t] = 0;
kew.push({0, t});
while (!kew.empty()){
auto k = kew.top();
kew.pop();
if (revdist[k.se] < k.fi) continue;
for (auto u : g[k.se]){
if (u.se + k.fi < revdist[u.fi]){
revdist[u.fi] = u.se + k.fi;
kew.push({revdist[u.fi], u.fi});
}
}
}
dist2[u] = 0;
kew.push({0, u});
while (!kew.empty()){
auto k = kew.top();
kew.pop();
if (dist2[k.se] < k.fi) continue;
for (auto u : g[k.se]){
int cost = u.se;
if (dist[k.se] + u.se + revdist[u.fi] == dist[t] || revdist[k.se] + u.se + dist[u.fi] == revdist[s])
cost = 0;
if (cost + k.fi < dist2[u.fi]){
dist2[u.fi] = cost + k.fi;
kew.push({dist2[u.fi], u.fi});
}
}
}
cout << dist2[v];
// for (int i = 1; i <= n; i++){
// cout << dist[i] << " " << revdist[i] << "\n";
// }
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... |