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>
using namespace std;
//using namespace __gnu_pbds;
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define russian setlocale(LC_ALL,"Russian_Russia.20866");
#define file freopen("onlyone.in", "r", stdin), freopen("onlyone.out", "w", stdout);
#define ll long long
//#define int long long
#define ull unsigned long long
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define all(s) s.begin(), s.end()
#define pb push_back
#define ins insert
#define mp make_pair
#define sz(x) x.size()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mem(x) memset(x, 0, sizeof(x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 100010;
const ll M = 600000;
const ll block = 316;
const ll mod = 1e9 + 7;
const ll P = 263;
const ld pi = acos(-1);
const ll inf = 1e9;
ll add(ll a, ll b) {
if(a + b < 0) return a + b + mod;
if(a + b >= mod) return a + b - mod;
return a + b;
}
ll sub(ll a, ll b) {
return (a - b + mod) % mod;
}
ll mul(ll a, ll b) {
return a * 1LL * b % mod;
}
ll binpow(ll a, ll n) {
ll res = 1;
while(n) {
if (n & 1) res = mul(res, a);
a = mul(a, a);
n >>= 1;
}
return res;
}
ll inv(ll x) {
return binpow(x, mod - 2);
}
int n, m, s, t, u, v;
int p[N];
vector<pii> g[N];
ll dijikstra(int st, int en) {
vector<ll> dist(n + 1, LLONG_MAX);
dist[st] = 0LL;
priority_queue<pair<ll, int>> q;
q.push({0LL, st});
while(!q.empty()) {
int v = q.top().S;
ll d = -q.top().F;
q.pop();
if(d > dist[v]) continue;
for(auto to: g[v]) {
if(dist[to.F] > dist[v] + to.S) {
p[to.F] = v;
dist[to.F] = dist[v] + to.S;
q.push({-dist[to.F], to.F});
}
}
}
return dist[en];
}
void solve() {
cin >> n >> m;
cin >> s >> t;
cin >> u >> v;
while(m--) {
int v1, v2, c;
cin >> v1 >> v2 >> c;
g[v1].pb({v2, c});
g[v2].pb({v1, c});
}
dijikstra(s, t);
int k = t;
while(p[k] != 0) {
for(int j = 0; j < (int)sz(g[k]); j++) {
if(g[k][j].F == p[k]) {
g[k][j].S = 0;
break;
}
}
for(int j = 0; j < (int)sz(g[p[k]]); j++) {
if(g[p[k]][j].F == k) {
g[p[k]][j].S = 0;
break;
}
}
k = p[k];
}
cout << dijikstra(u, v) << '\n';
}
signed main() {
speed;
//file
int test = 1;
//cin >> test;
while(test--) {
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... |