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>
using namespace std;
#define int long long
#define pii pair<int, int>
#define pipii pair<int, pii>
int32_t main()
{
int n, m;
cin >> n >> m;
int s, t, u, v;
cin >> s >> t >> u >> v;
s--; t--; u--; v--;
vector<vector<pii>> graph(n);
for (int i = 0; i < m; i++)
{
int a, b, c;
cin >> a >> b >> c;
a--; b--;
graph[a].push_back({b, c});
graph[b].push_back({a, c});
}
vector<int> dists(n, 1e18);
vector<int> distt(n, 1e18);
priority_queue<pii, vector<pii>, greater<pii>> pq;
pq.push({0, s});
while (pq.size())
{
int d, i;
tie(d, i) = pq.top();
pq.pop();
if (dists[i]!=1e18) continue;
dists[i] = d;
for (pii ele:graph[i])
{
pq.push({d+ele.second, ele.first});
}
}
pq.push({0, t});
while (pq.size())
{
int d, i;
tie(d, i) = pq.top();
pq.pop();
if (distt[i]!=1e18) continue;
distt[i] = d;
for (pii ele:graph[i])
{
pq.push({d+ele.second, ele.first});
}
}
int mn = 1e18;
for (int i = 0; i < n; i++) mn = min(mn, dists[i]+distt[i]);
vector<vector<int>> distu(n, vector<int>(4, 1e18));
priority_queue<pipii, vector<pipii>, greater<pipii>> npq;
npq.push({0, {u, 0}});
while (npq.size())
{
int d;
pii is;
tie(d, is) = npq.top();
int i = is.first;
int s = is.second;
npq.pop();
if (distu[i][s]!=1e18) continue;
distu[i][s] = d;
for (pii ele:graph[i])
{
if (s==0) npq.push({d+ele.second, {ele.first, 0}});
else npq.push({d+ele.second, {ele.first, 3}});
if (dists[ele.first]+distt[ele.first]==mn && dists[i]+distt[i]==mn)
{
if (s==0)
{
if (dists[ele.first]<dists[i]) npq.push({d, {ele.first, 1}});
else npq.push({d, {ele.first, 2}});
}
if (s==1)
{
if (dists[ele.first]<dists[i]) npq.push({d, {ele.first, 1}});
}
if (s==2)
{
if (dists[ele.first]>dists[i]) npq.push({d, {ele.first, 2}});
}
}
}
}
mn = 1e18;
for (int i = 0; i < 4; i++)
{
mn = min(mn, distu[v][i]);
}
cout << mn;
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... |