이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define F first
#define S second
#define PB push_back
#define FOR(i, u, v) for (int i = u; i <= v; i++)
#define FORD(i, v, u) for (int i = v; i >= u; i--)
#define N 100005
#define maxc 1ll*100000000000000007
#define ll long long
using namespace std;
int n, m, S, T, U, V, in[N];
ll ans[N], ans2[N], d[5][N];
vector<int> g[N];
vector<pii> a[N];
void setup()
{
cin >> n >> m >> S >> T >> U >> V;
FOR(i, 1, m)
{
int u, v, w; cin >> u >> v >> w;
a[u].PB(mp(v, w));
a[v].PB(mp(u, w));
}
}
void IJK(int s, ll dis[])
{
FOR(i, 1, n) dis[i] = maxc;
dis[s] = 0;
priority_queue<pair<ll, int> > q;
q.push(mp(0, s));
while (!q.empty())
{
int u = q.top().S;
ll l = -q.top().F;
q.pop();
if (dis[u] < l) continue;
for (auto z : a[u])
{
int v = z.F;
int w = z.S;
if (dis[v] > l + w)
{
dis[v] = l + w;
q.push(mp(-dis[v], v));
}
}
}
}
void add_edge(int u, int v)
{
g[v].PB(u);
in[u]++;
}
void solve()
{
IJK(S, d[1]);
IJK(T, d[2]);
FOR(u, 1, n)
for (auto z : a[u])
{
int v = z.F;
int w = z.S;
if (d[1][u] + d[2][v] + w == d[1][T])
add_edge(u, v);
}
IJK(U, d[3]);
IJK(V, d[4]);
FOR(i, 1, n) ans[i] = d[4][i], ans2[i] = d[3][i];
queue<int> q;
q.push(T);
ll res = d[3][V];
while (!q.empty())
{
int u = q.front(); q.pop();
ll l = ans[u];
ll l2 = ans2[u];
res = min(res, l + d[3][u]);
res = min(res, l2 + d[4][u]);
for (auto v : g[u])
{
ans[v] = min(ans[v], ans[u]);
ans2[v] = min(ans2[v], ans2[u]);
in[v]--;
if (in[v] == 0) q.push(v);
}
}
cout <<res;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("INP.TXT", "r", stdin);
setup();
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... |