This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>
#define ll long long
#define int long long
#define all(v) v.begin(), v.end()
#define nl '\n'
#define pb push_back
#define sz(s) (int)(s).size()
#define f first
#define s second
using namespace std;
const ll N = 1e5 + 50, MX = 1e18;
bool was[N];
void solve(){
ll n,m;
cin >> n >> m;
vector <pair <int, int> > g[n + 1];
ll s, t, u, v;
cin >> s >> t >> u >> v;
for(int i = 1; i <= n; i++){
ll a, b, x;
cin >> a >> b >> x;
g[a].pb({b,x});
g[b].pb({a, x});
}
if(n <= 300) {
ll d[n+1][n + 1];
for(int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
d[i][j] = MX;
}
}
for(int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++) {
was[j] = 0;
}
d[i][i] = 0;
priority_queue< pair<long long, int> > s;
s.push({0, i});
while(s.size() != 0) {
int v = s.top().second;
s.pop();
if(was[v]) continue;
was[v] = 1;
for(auto [to, w]: g[v]) {
if(i == 6){
cout << d[i][to] << ' ' << to << " " << w << " " << d[i][v] << " " << v << nl;
}
if(d[i][to] > d[i][v] + w) {
//s.erase({d[to], to});
d[i][to] = d[i][v] + w;
s.push({-d[i][to], to});
}
}
}
}
ll ans = d[u][v];
cout << d[s][t] << nl;
//cout << ds[3] << " " << dt[5] << nl;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (d[s][i] + d[t][j] + d[i][j] == d[s][t] || d[s][j] + d[t][i] + d[i][j] == d[s][t]) {
ans = min(ans, d[u][i] + d[v][j]);
}
}
}
cout << ans << nl;
}
}
signed main(){
//freopen("lca.in", "r", stdin);
//freopen("lca.out", "w", stdout);
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll ql=1;
//cin >> ql;
//tst++;
while(ql--){
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... |