#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define io(x) if (fopen(x".inp","r")) {freopen(x".inp","r",stdin),freopen(x".out","w",stdout);}
#define mem(c, x) memset(c, x, sizeof(c))
#define all(c) c.begin(), c.end()
#define bit(i,j) ((i >> j) & 1)
#define pb push_back
#define se second
#define fi first
#define el '\n'
using namespace std;
template<class T> bool maximize(T &a, const T &b) { return (a < b ? a = b, 1 : 0); }
template<class T> bool minimize(T &a, const T &b) { return (a > b ? a = b, 1 : 0); }
int dx[8] = {0, 1, 0,-1, 1, 1,-1,-1};
int dy[8] = {1, 0,-1, 0, 1,-1,-1, 1};
const int maxn = 2e5 + 2;
const int Inf = 2e9 + 7;
const ll Infll = 1e18 + 9;
const ll Mod = 1e9 + 7;
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
ll disU[maxn], disV[maxn], disT[maxn], disS[maxn], dp[maxn], dp2[maxn];
int U, V, S, T, n, m;
vector<pll> adj[maxn];
vector<int> bel[maxn], topo;
bool vst[maxn];
void dijkstra(int source, ll dis[]) {
for (int i=1; i<=n; i++) dis[i] = Infll;
dis[source] = 0;
priority_queue<pll, vector<pll>, greater<pll>> q;
q.push({0, source});
while (q.size()) {
ll kc = q.top().fi, u = q.top().se; q.pop();
if (kc > dis[u]) continue;
for (auto v : adj[u]) {
if (minimize(dis[v.fi], dis[u] + v.se)) {
q.push({dis[v.fi], v.fi});
}
}
}
}
void dfs(int u) {
vst[u] = 1;
for (int v : bel[u]) {
if (vst[v]) continue;
dfs(v);
}
topo.pb(u);
}
void newGraph() {
for (int u=1; u<=n; u++) {
for (auto v : adj[u])
if (disS[u] + v.se + disT[v.fi] == disS[T]) {
bel[u].pb(v.fi);
}
}
for (int i=1; i<=n; i++) {
if (!vst[i]) {
dfs(i);
}
}
}
void solve() {
cin >> n >> m >> S >> T >> U >> V;
for (int i=1; i<=m; i++) {
int x,y,z; cin >> x >> y >> z;
adj[x].pb({y, z});
adj[y].pb({x, z});
}
dijkstra(S, disS);
dijkstra(T, disT);
dijkstra(U, disU);
dijkstra(V, disV);
newGraph();
reverse(all(topo));
for (int i=1; i<=n; i++) dp[i] = dp2[i] = Infll;
dp[S] = disV[S];
dp2[S] = disU[S];
for (int u : topo) {
for (int v : bel[u]) {
minimize(dp[v], min(dp[u], disV[v]));
minimize(dp2[v], min(dp2[u], disU[v]));
}
}
ll res = disU[V];
for (int i=1; i<=n; i++) {
minimize(res, disU[i] + dp[i]);
minimize(res, disV[i] + dp2[i]);
}
cout << res;
}
signed main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
io("task");
solve();
return (0 ^ 0);
}
Compilation message (stderr)
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:6:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
6 | #define io(x) if (fopen(x".inp","r")) {freopen(x".inp","r",stdin),freopen(x".out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:111:5: note: in expansion of macro 'io'
111 | io("task");
| ^~
commuter_pass.cpp:6:85: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
6 | #define io(x) if (fopen(x".inp","r")) {freopen(x".inp","r",stdin),freopen(x".out","w",stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:111:5: note: in expansion of macro 'io'
111 | io("task");
| ^~
# | 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... |