This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* be name khoda */
#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <queue>
using namespace std;
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif
typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;
#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))
#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
const ll MOD = 1000000007;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;
#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD
// -----------------------------------------------------------------------
const ll maxn = 100010;
ll n, m, S, T, U, V;
vpii g[maxn];
vi dag[maxn];
ll dp[maxn], ans;
ll ds[maxn], dt[maxn], du[maxn], dv[maxn];
priority_queue<pii, vpii, greater<pii>> pq;
bool vis[maxn];
void dijkstra(ll s, ll *d) {
memset(d, 20, sizeof ds);
memset(vis, 0, sizeof vis);
d[s] = 0;
pq.push({d[s], s});
while (!pq.empty()) {
ll x = pq.top().S;
pq.pop();
if (vis[x]) continue;
vis[x] = true;
for (auto [y, w] : g[x]) {
if (d[x] + w < d[y]) {
d[y] = d[x] + w;
pq.push({d[y], y});
}
}
}
}
void dfs(ll x) {
vis[x] = true;
dp[x] = dv[x];
for (auto y : dag[x]) {
if (!vis[y]) dfs(y);
smin(dp[x], dp[y]);
}
smin(ans, du[x] + dp[x]);
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m >> S >> T >> U >> V; --S, --T, --U, --V;
fori (i, m) {
ll a, b, c; cin >> a >> b >> c; --a, --b;
g[a].eb(b, c), g[b].eb(a, c);
}
dijkstra(S, ds);
dijkstra(T, dt);
dijkstra(U, du);
dijkstra(V, dv);
fori (x, n) {
for (auto [y, w] : g[x]) {
if (ds[x] + w + dt[y] == ds[T]) dag[x].eb(y);
}
}
ans = du[V];
memset(vis, 0, sizeof vis);
dfs(S);
swap(du, dv);
memset(vis, 0, sizeof vis);
dfs(S);
cout << ans << '\n';
}
# | 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... |