// ~~ icebear love atttttttttttt ~~
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define rep(i, n) for(int i=0; i<(n); ++i)
#define red(i, n) for(int i=(n)-1; i>=0; --i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebearat"
const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll LLinf = 1e18 + 27092008;
const int N = 1e5 + 5;
int n, m, U, V, S, T;
vector<ii> G[N];
int dist[4][N], f[N][2], dp[N];
vector<int> adj[N];
void dijkstra(int id, int src) {
priority_queue<ii, vector<ii>, greater<ii>> pq;
memset(dist[id], 0x3f, sizeof dist[id]);
dist[id][src] = 0;
pq.push(mp(0, src));
while(!pq.empty()) {
int du, u; tie(du, u) = pq.top(); pq.pop();
if (du != dist[id][u]) continue;
for(ii e : G[u]) {
int v, w; tie(v, w) = e;
if (dist[id][v] > dist[id][u] + w) {
dist[id][v] = dist[id][u] + w;
pq.push(mp(dist[id][v], v));
}
}
}
}
int dijkstra2(int id, int src) {
priority_queue<ii, vector<ii>, greater<ii>> pq;
FOR(i, 1, n) {
dist[id][i] = LLinf;
f[i][0] = f[i][1] = LLinf;
}
dist[id][src] = 0;
pq.push(mp(0, src));
f[src][0] = dist[0][src];
f[src][1] = dist[1][src];
while(!pq.empty()) {
int du, u;
tie(du, u) = pq.top(); pq.pop();
if (du != dist[id][u]) continue;
for(ii e : G[u]) {
int v, w; tie(v, w) = e;
if (dist[id][v] > dist[id][u] + w) {
dist[id][v] = dist[id][u] + w;
f[v][0] = min(f[u][0], dist[0][v]);
f[v][1] = min(f[u][1], dist[1][v]);
pq.push(mp(dist[id][v], v));
} else
if (dist[id][v] == dist[id][u] + w && min(dist[0][v], f[u][0]) + min(dist[1][v], f[u][1]) < f[v][0] + f[v][1]) {
f[v][0] = min(dist[0][v], f[u][0]);
f[v][1] = min(dist[1][v], f[u][1]);
}
}
}
return (src == S ? f[T][0] + f[T][1] : f[S][0] + f[S][1]);
}
void solve() {
cin >> n >> m >> S >> T >> U >> V;
FOR(i, 1, m) {
int u, v, w;
cin >> u >> v >> w;
G[u].pb(mp(v, w));
G[v].pb(mp(u, w));
}
dijkstra(0, U);
dijkstra(1, V);
cout << min({dist[0][V], dijkstra2(2, S), dijkstra2(3, T)});
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while(tc--) solve();
return 0;
}
Compilation message (stderr)
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |