#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class A, class B>
bool maximize(A &a, const B b) {
if (a < b) {
a = b;
return true;
} return false;
}
template <class A, class B>
bool minimize(A &a, const B b) {
if(a > b) {
a = b;
return true;
} return false;
}
using pII = pair <int, int>;
using vI = vector <int>;
using vL = vector <long long>;
using pLI = pair <long long, int>;
#define BIT(mask, i) ((mask >> (i)) & 1)
#define MASK(a) (1LL<<(a))
#define FOR(i, a, b) for(int i = a; i <= (int)b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int)b; i--)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
int n, m, A, B, C, D;
vector <pair <int, int>> g[maxn], adj[maxn];
ll distA[maxn], distB[maxn], dp[maxn];
void dijkstra(int st, ll dist[])
{
#define bg pair <long long, int>
priority_queue <bg, vector <bg>, greater <bg>> pq;
FOR(i, 1, n) dist[i] = 1e18;
pq.push({dist[st] = 0, st});
while(sz(pq))
{
ll cost = pq.top().first;
int u = pq.top().second;
pq.pop();
if(cost > dist[u]) continue;
for(pair <int, int> &it : g[u])
{
int v = it.fi, w = it.se;
if(minimize(dist[v], cost + w)) pq.push({cost + w, v});
}
}
}
void process()
{
cin >> n >> m >> A >> B >> C >> D;
FOR(i, 1, m)
{
int u, v, w; cin >> u >> v >> w;
g[u].pb({v, w}); g[v].pb({u, w});
}
dijkstra(A, distA);
dijkstra(B, distB);
FOR(i, 1, n)
{
for(const pII &it : g[i])
{
int j = it.fi, w = it.se;
if(distA[i] >= 1e18 || distB[j] >= 1e18) continue;
if(distA[i] + w + distB[j] == distA[B])
{
adj[i].push_back({j, 0});
} else adj[i].push_back({j, w});
}
}
FOR(i, 1, n) dp[i] = 1e18;
dp[C] = 0;
priority_queue <bg, vector <bg>, greater <bg>> pq;
pq.push({0, C});
while(sz(pq))
{
ll cost = pq.top().first;
int u = pq.top().second;
pq.pop();
if(cost > dp[u]) continue;
for(const pII &it : adj[u])
{
int v = it.fi, w = it.se;
if(minimize(dp[v], cost + w)) pq.push({cost + w, v});
}
}
cout << dp[D];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
#define taskname "kieuoanh"
if(fopen(taskname".inp", "r"))
{
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
int tc = 1; /// cin >> tc;
while (tc--) process();
return 0;
}
Compilation message (stderr)
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:113:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
113 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:114:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
114 | freopen(taskname".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... |