이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)
typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;
template <typename T> inline void Read(T &x) {
char c = getchar();
bool f = false;
for (x = 0; !isdigit(c); c = getchar()) {
if (c == '-') {
f = true;
}
}
for (; isdigit(c); c = getchar()) {
x = x * 10 + c - '0';
}
if (f) {
x = -x;
}
}
template <typename T> inline bool CheckMax(T &a, const T &b) {
return a < b ? a = b, true : false;
}
template <typename T> inline bool CheckMin(T &a, const T &b) {
return a > b ? a = b, true : false;
}
const int N = 100005;
const LL inf = 1LL << 60;
LL ans, f[N], g[N], S[N], T[N], U[N], V[N];
priority_queue <pair <LL, int>> q;
int n, m, s, t, u, v, top, seq[N];
vector <pii> adj[N];
bool vis[N];
inline void Dijkstra(int s, LL *d) {
for (int i = 1; i <= n; ++i) {
vis[i] = false, d[i] = inf;
}
d[s] = 0, q.push(mp(0, s));
while (!q.empty()) {
int x = q.top().Y;
q.pop();
if (vis[x]) {
continue;
}
vis[x] = true;
for (auto e : adj[x]) {
if (CheckMin(d[e.X], d[x] + e.Y)) {
q.push(mp(-d[e.X], e.X));
}
}
}
}
int main() {
#ifdef wxh010910
freopen("d.in", "r", stdin);
#endif
Read(n), Read(m), Read(s), Read(t), Read(u), Read(v);
for (int i = 1, x, y, w; i <= m; ++i) {
Read(x), Read(y), Read(w);
adj[x].pb(mp(y, w)), adj[y].pb(mp(x, w));
}
Dijkstra(s, S), Dijkstra(t, T), Dijkstra(u, U), Dijkstra(v, V), ans = u[V];
for (int i = 1; i <= n; ++i) {
if (S[i] + T[i] == S[t]) {
seq[++top] = i, f[i] = U[i], g[i] = V[i];
}
}
sort(seq + 1, seq + top + 1, [&](const int &x, const int &y) {
return S[x] < S[y];
});
for (int i = 1; i <= top; ++i) {
int x = seq[i];
for (auto e : adj[x]) {
if (S[e.X] + e.Y == S[x]) {
CheckMin(f[x], f[e.X]), CheckMin(g[x], g[e.X]);
}
}
CheckMin(ans, f[x] + V[x]), CheckMin(ans, g[x] + U[x]);
}
printf("%lld\n", ans);
#ifdef wxh010910
Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
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... |