This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout)
#define fi first
#define se second
#define endl "\n"
#define len(s) int32_t(s.length())
#define MASK(k)(1LL<<(k))
#define TASK "test"
#define int long long
using namespace std;
typedef tuple<int, int, int> tpiii;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef long long ll;
const long long OO = 1e18;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MX = 200005;
int n, m;
int S, T, U, V;
vector<pii> G[MX];
void nhap(){
cin >> n >> m;
cin >> S >> T >> U >> V;
for(int i=1; i<=m; i++){
int u, v, c;
cin >> u >> v >> c;
G[u].push_back({v, c});
G[v].push_back({u, c});
}
}
void dijkstra(int u, int *d){
for(int i=1; i<=n; i++) d[i] = 1e18;
priority_queue<pii> Q;
Q.push({0, u});
d[u] = 0;
while(Q.size()){
int du, u;
tie(du, u) = Q.top();
du = -du;
Q.pop();
if(du != d[u]) continue;
for(pii &tmp: G[u]){
int v, c; tie(v, c) = tmp;
c += du;
if(c < d[v]){
d[v] = c;
Q.push({-c, v});
}
}
}
}
int dS[MX];
int dT[MX];
int dU[MX];
int dV[MX];
int f[MX];
void solve(){
dijkstra(S, dS);
dijkstra(T, dT);
dijkstra(U, dU);
dijkstra(V, dV);
int ans = dU[V];
{
memset(f, 0x3f, sizeof f);
bitset<MX> vist = 0;
vector<int> vt(n);
for(int i=1; i<=n; i++) vt[i-1] = i;
function<bool(const int &, const int &)> comp = [&](const int &a, const int &b){
return dS[a] < dS[b];
};
sort(vt.begin(), vt.end(), comp);
for(int u: vt) if(dS[u] + dT[u] == dS[T]){
f[u] = dU[u];
for(pii tmp: G[u]){
int v, c; tie(v, c) = tmp;
if(dS[v] + c == dS[u]) f[u] = min(f[u], f[v]);
}
ans = min(ans, f[u] + dV[u]);
}
}
{
memset(f, 0x3f, sizeof f);
bitset<MX> vist = 0;
vector<int> vt(n);
for(int i=1; i<=n; i++) vt[i-1] = i;
function<bool(const int &, const int &)> comp = [&](const int &a, const int &b){
return dS[a] < dS[b];
};
sort(vt.begin(), vt.end(), comp);
for(int u: vt) if(dS[u] + dT[u] == dS[T]){
f[u] = dV[u];
for(pii tmp: G[u]){
int v, c; tie(v, c) = tmp;
if(dS[v] + c == dS[u]) f[u] = min(f[u], f[v]);
}
ans = min(ans, f[u] + dU[u]);
}
}
cout << ans;
}
int32_t main(){
fastIO;
//file(TASK);
nhap();
solve();
return 0;
}
Compilation message (stderr)
commuter_pass.cpp: In function 'void solve()':
commuter_pass.cpp:76:20: warning: variable 'vist' set but not used [-Wunused-but-set-variable]
76 | bitset<MX> vist = 0;
| ^~~~
commuter_pass.cpp:94:20: warning: variable 'vist' set but not used [-Wunused-but-set-variable]
94 | bitset<MX> vist = 0;
| ^~~~
# | 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... |