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 F first
#define S second
#define mkp make_pair
#define MEM(x) memset(x, 0, sizeof(x))
#define SZ(x) int(x.size())
#define ALL(x) begin(x), end(x)
#define REP(i,n) for( int i = 0; i < n; ++i )
#define FOR(i,a,b) for( int i = (a); i <= b; ++i )
#define RFOR(i,a,b) for( int i = (a); i >= b; --i )
#define EB emplace_back
#define EP emplace
#ifdef DEBUG
template<typename T> void _DO(T&&x){cerr << x << '\n'}
template<typename A, typename ...B> void _OD(A&&a, B&&...b){cerr << a <<','; _DO(b...);};
#define de(...) do{\
fprintf(stderr, "%s-%d (%s):", __func__, __LINE__, #__VA_ARGS__);\
_DO(__VA_ARGS__);\
}while(0);
#else
#define de(...)
#endif
typedef long long ll;
typedef pair<int,int> pii;
typedef array<ll, 3> arr;
template<typename T>
using V = vector<T>;
constexpr int mxN = 3e5+1;
constexpr ll inf = 1e18;
vector<arr> graph[ mxN ];
struct ShortPath {
int st;
ll dis[ mxN ];
void DO() {
priority_queue< arr, V<arr>, greater<arr>> pq;
pq .EP( arr{0, st, st} );
while( !pq.empty() ) {
auto a = pq.top(); pq.pop();
if( dis[ a[1] ] != inf ) continue;
dis[ a[1] ] = a[0];
for( auto &i : graph[ a[1] ] ) {
if( dis[ i[1] ] != inf ) continue;
pq.EP( arr{ a[0]+i[0], i[1], a[1] });
}
}
};
ll operator() (int t ) {
return dis[ t ] ;
};
ShortPath( int _st ) {
st = _st;
for( auto &i : dis ) i = inf;
DO();
};
};
inline void solve() {
int N, M; cin >> N >> M;
int s, t; cin >> s >> t;
int u, v; cin >> u >> v;
REP(edge, M ){
int a, b, c;
cin >> a >> b >> c;
graph[ a ].EB( arr{c,b,edge+1} );
graph[ b ].EB( arr{c,a,edge+1} );
}
// make shortest path
ShortPath froms(s), fromv(v), fromt(t), fromu(u);
ll ans = fromu(v)*2;
ans = min( {
froms(u) + fromt(v) + fromu(v) - froms(t),
froms(v) + fromt(u) + fromu(v) - froms(t),
ans
});
// check if (u, v) is on the shortest path
/*
for( int i = 1; i <= N; ++i ) {
cout << froms(i) << ' ';
}
cout << '\n';
for( int i = 1; i <= N; ++i ) {
cout << fromt(i) << ' ';
}
cout << '\n';
*/
cout << ans / 2<< '\n';
}
int main () {
int T = 1;
#ifdef Local
cin >> T;
#endif
while(T--) 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... |