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 <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <numeric>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <complex>
#include <climits>
#include <random>
using namespace std;
#define ll long long
#define pb push_back
#define ull unsigned long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(x) x.rbegin(), (x).rend()
#define int long long
const ll mod = 1e9 + 7;
const int block = 450;
const ll LINF = 1e16;
const int INF = 1e8;
ll add(ll a, ll b){
ll x = a + b;
if(x < 0) x += mod;
if(x >= mod) x -= mod;
return x;
}
ll mul(ll a, ll b){
return (a * b) % mod;
}
ll sub(ll x, ll y){
return add(x, -y);
}
ll binpow(ll a, ll b) {
ll res = 1LL;
while (b > 0) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int n, m;
int s, t, x, y;
map<pair<int, int>, ll> mp;
vector<int> g[100005];
ll dist[100005];
int pred[100005];
void djikstra(int a){
for(int i = 1; i <= n; i++) dist[i] = INF;
dist[a] = 0LL;
priority_queue<pair<ll, int>> q;
q.push({0LL, a});
while(!q.empty()){
ll d = -q.top().F;
int v = q.top().S;
q.pop();
if(d > dist[v]){
continue;
}
for(auto i : g[v]){
int x = v, y = i;
if(dist[i] > d + mp[{min(x, y), max(x, y)}]){
dist[i] = d + mp[{min(x, y), max(x, y)}];
pred[i] = v;
q.push({-dist[i], i});
}
}
}
}
void solve(){
cin >> n >> m;
cin >> s >> t;
cin >> x >> y;
for(int i = 1; i <= m; i++){
int v, u;
ll c;
cin >> v >> u >> c;
mp[{min(v, u), max(v, u)}] = c;
g[v].pb(u);
g[u].pb(v);
}
pred[s] = 0;
djikstra(s);
int v = t;
while(1){
int prev = v;
v = pred[v];
if(!v) break;
mp[{min(v, prev), max(v, prev)}] = 0LL;
}
djikstra(x);
cout << dist[y];
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int xach = 1;
//cin >> xach;
while(xach--) solve();
}
# | 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... |