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 endl "\n"
using namespace std;
typedef long long ll;
const int N = 2e5 + 15;
const ll INF = 1e18;
int n, m;
int U, V, S, T;
vector<pair<int, ll>> g[N];
// U: 1, V: 2, S: 3, T: 4
vector<ll> dist[5];
vector<int> adj[N];
ll ans = 0;
void dijk(vector<ll>& dist, int root){
dist[root] = 0;
priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
pq.push({0,root});
while(!pq.empty()){
ll wu; int u; tie(wu,u) = pq.top(); pq.pop();
if(wu > dist[u]) continue;
for(auto [v, wv] : g[u]){
if(dist[v] > dist[u] + wv){
dist[v] = dist[u] + wv;
pq.push({dist[v], v});
}
}
}
}
void build(int u){
for(auto [v, wv] : g[u]){
if(dist[1][u] + wv + dist[2][v] == dist[1][V]){
adj[u].push_back(v);
build(v);
}
}
}
// best[i][1] = max dist[i] -> s | best[i][2] = max dist[i] -> t
ll best[N][3];
void dfs(int u){
best[u][1] = dist[3][u];
best[u][2] = dist[4][u];
for(int v : adj[u]){
dfs(v);
best[u][1] = min(best[u][1], best[v][1]);
best[u][2] = min(best[u][2], best[v][2]);
}
ans = min(ans, dist[3][u] + best[u][2]);
ans = min(ans, dist[4][u] + best[u][1]);
}
void solve(){
cin >> n >> m >> U >> V >> S >> T;
for(int i = 1; i <= m; i++){
int u, v, w; cin >> u >> v >> w;
g[u].push_back({v,w});
g[v].push_back({u,w});
}
for(int i = 1; i <= 4; i++) dist[i].resize(n+1, INF);
dijk(dist[1], U);
dijk(dist[2], V);
dijk(dist[3], S);
dijk(dist[4], T);
build(U);
ans = dist[3][T];
dfs(U);
cout << ans;
}
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0); cout.tie(0);
#define task "bus"
if(fopen(task".INP", "r")){
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
int t; t = 1; //cin >> t;
while(t--) solve();
}
Compilation message (stderr)
commuter_pass.cpp: In function 'void dijk(std::vector<long long int>&, int)':
commuter_pass.cpp:27:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
27 | for(auto [v, wv] : g[u]){
| ^
commuter_pass.cpp: In function 'void build(int)':
commuter_pass.cpp:37:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
37 | for(auto [v, wv] : g[u]){
| ^
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | freopen(task".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
93 | 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... |