#include <bits/stdc++.h>
#include <iostream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define vt vector
#define heap priority_queue
#define dq deque
#define maxN 200005
#define maxA 20000005
#define maxM 5005
#define fi first
#define se second
#define For(i, j, n) for(int i=(j);i<=(n);i++)
#define Forr(i, n, j) for(int i=(n);i>=(j);i--)
#define pb push_back
#define pf push_front
#define reset(x,val) memset((x),(val),sizeof(x))
#define bit(i,j) ((i>>j)&1ll)
#define mask(i) (1ll<<i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
/* I LOVE WHAT IM DOING AND ILL KEEP DOING TS UNTIL I GET THERE, NOT JUST ABT CODING */
typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag,
__gnu_pbds::tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef pair<ll, ll> ii;
const string NAME = "c++";
void io() {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
ll bpow(ll x, ll n, ll modd){if (n==0) return 1; ll s = bpow(x, n/2, modd); s = (s*s)%modd;
if (n%2) return (s*x)%modd; else return s%modd;}
ll pairing(ll x) {return x*(x-1)/2;}
ll sumto(ll x) {return x*(x+1)/2;}
const ll inf = (ll)1e18;
const ll neg_inf = -(ll)1e18;
const ll mod = 1e9+7;
/* modular inverse by bpow(x, mod -2)%mod*/
//------
//------
/* debugging tips
1. clear all data structure
2. clear var
3. check corner case
4. check loops
5. check mod
6. if clear, then avoid abusing built-in clear function.
7. making mistakes are tolerated but doing it twice is not, better KMS
*/
//any function here
ll S, T, U, V;
ll n, m;
struct Edge
{
ll v, c;
};
struct Node
{
ll u, d;
};
struct cmp
{
bool operator() (Node a, Node b)
{
return a.d > b.d;
}
};
vt<Edge> a[maxN];
vt<ll> parent[maxN], children[maxN];
ll dS[maxN], dU[maxN], dV[maxN];
bool ok[maxN];
void dij(ll dist[], ll s)
{
heap<Node, vt<Node>, cmp> h;
vt<bool> visited(n+1, false);
For (i, 1, n) dist[i] = inf;
dist[s] = 0;
h.push({s, dist[s]});
while(!h.empty())
{
Node x = h.top(); h.pop();
ll u = x.u;
if (visited[u])
continue;
visited[u] = true;
for (Edge e:a[u])
{
ll v = e.v;
ll c = e.c;
if (dist[v]>dist[u]+c){
dist[v] = dist[u]+c;
if (s == S) {parent[v].clear(); parent[v].pb(u);}
h.push({v, dist[v]});
}
else if (dist[v]==dist[u]+c)
{
if (s==S) parent[v].pb(u);
}
}
}
}
ll bst[2][maxN];
ll dpF(ll u)
{
if (bst[0][u]!=-1) return bst[0][u];
bst[0][u] = dV[u];
for (int v:children[u])
{
bst[0][u] = min(bst[0][u], dpF(v));
}
return bst[0][u];
}
ll dpB(ll u)
{
if (bst[1][u]!=-1) return bst[1][u];
bst[1][u] = dV[u];
for (int v:parent[u])
{
bst[1][u] = min(bst[1][u], dpB(v));
}
return bst[1][u];
}
void solve()
{
cin>>n>>m>>S>>T>>U>>V;
For (i, 1, m)
{
ll u, v, c;
cin>>u>>v>>c;
a[u].pb({v, c});
a[v].pb({u, c});
}
dij(dS, S);
dij(dU, U);
dij(dV, V);
ll ans = dU[V];
queue<ll> q; q.push(T);
while(!q.empty())
{
ll u = q.front(); q.pop();
if (!ok[u])
{
ok[u] = true;
for (ll v:parent[u])
{
children[v].pb(u);
q.push(v);
}
}
}
For (i, 1, n)
{
bst[0][i] = bst[1][i] = -1;
}
For (i, 1, n)
{
if (ok[i])
{
ans = min(ans, dU[i] + min(dpF(i), dpB(i)));
}
}
cout<<ans<<endl;
}
int main()
{
io();
#ifndef ONLINE_JUDGE
freopen((NAME + ".INP").c_str(), "r", stdin);
freopen((NAME + ".OUT").c_str(), "w", stdout);
#endif
ll T = 1;
//cin>>T;
while(T--) solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:172:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
172 | freopen((NAME + ".INP").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:173:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
173 | freopen((NAME + ".OUT").c_str(), "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... |