This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Arayi
#include <bits/stdc++.h>
#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jigglypuff
#define ld long double
#define itn int
#define pir pair<int, int>
#define all(x) (x).begin(), (x).end()
#define str string
#define enl endl
#define en endl
#define cd complex<long double>
#define vcd vector<cd>
#define vii vector<int>
#define vlli vector<lli>
using namespace std;
lli gcd(lli a, lli b) { return (b == 0LL ? a : gcd(b, a % b)); }
ld dist(ld x, ld y1, ld x2, ld y2)
{
return sqrt((x - x2) * (x - x2) + (y1 - y2) * (y1 - y2));
}
lli S(lli a)
{
return (a * (a + 1LL)) / 2;
}
mt19937 rnd(363542);
char vow[] = {'a', 'e', 'i', 'o', 'u'};
int dx[] = {0, -1, 0, 1, -1, -1, 1, 1, 0};
int dy[] = {-1, 0, 1, 0, -1, 1, -1, 1, 0};
char dc[] = {'R', 'D', 'L', 'U'};
const int N = 1e6 + 20;
const lli mod = LLONG_MAX;
const ld pi = acos(-1);
const ld e = 1e-13;
const int T = 200;
lli bp(lli a, lli b = mod - 2LL)
{
lli ret = 1;
while (b)
{
if (b & 1)
ret *= a, ret %= mod;
a *= a;
a %= mod;
b >>= 1;
}
return ret;
}
ostream &operator<<(ostream &c, pir a)
{
c << a.fr << " " << a.sc;
return c;
}
template <class T>
void maxi(T &a, T b)
{
a = max(a, b);
}
template <class T>
void mini(T &a, T b)
{
a = min(a, b);
}
int n, m;
int s, t, u, v;
vector<pair<int, lli>> g[N];
lli d[4][N], cl[N];
void f(int i1, int x)
{
priority_queue<pair<lli, int>> q;
for (int i = 1; i <= n; i++)
d[i1][i] = mod;
q.push(MP(0, x));
while (!q.empty())
{
auto p = q.top();
q.pop();
if (d[i1][p.sc] != mod)
continue;
d[i1][p.sc] = -p.fr;
for (auto p1 : g[p.sc])
{
if (d[i1][p1.fr] < mod)
continue;
q.push(MP(p.fr - p1.sc, p1.fr));
}
}
}
void dfs(int v, lli sm)
{
priority_queue<pair<lli, int>> q;
q.push(MP(0, v));
mini(cl[v], sm);
while (!q.empty())
{
auto f = q.top();
q.pop();
if (f.sc != v)
{
if (cl[f.sc] != mod)
continue;
cl[f.sc] = sm;
}
for (auto p : g[f.sc])
{
if (cl[p.fr] != mod)
continue;
if (d[0][p.fr] + d[1][p.fr] != d[0][t])
continue;
if (-f.fr + p.sc + d[0][p.fr] == d[0][v] || -f.fr + p.sc + d[1][p.fr] == d[1][v])
q.push(MP(f.fr - p.sc, p.fr));
}
}
}
int main()
{
fastio;
cin >> n >> m;
cin >> s >> t >> u >> v;
for (int i = 0; i < m; i++)
{
int a, b, c;
cin >> a >> b >> c;
g[a].ad(MP(b, c));
g[b].ad(MP(a, c));
}
f(0, s), f(1, t), f(2, u), f(3, v);
vector<pair<lli, int>> fp;
for (int i = 1; i <= n; i++)
{
cl[i] = mod;
if (d[0][i] + d[1][i] == d[0][t])
fp.ad(MP(d[3][i], i));
}
sort(all(fp));
for (auto p : fp)
{
dfs(p.sc, p.fr);
}
lli sum = d[2][v];
//cout << sum << endl;
for (int i = 1; i <= n; i++)
{
if (d[0][i] + d[1][i] == d[0][t])
{
mini(sum, d[2][i] + cl[i]);
//cout << i << " " << d[2][i] << " " << cl[i] << endl;
}
}
cout << sum << endl;
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... |