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 <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
vector<ll> dijkstra(int s, vector<vector<pair<ll, ll>>> &adj){
int n = adj.size();
vector<ll> dist(n+1, INF);
dist[s] = 0;
vector<bool> vis(n+1, false);
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
pq.push({0, s});
while(!pq.empty()){
ll d_u = pq.top().first;
int u = pq.top().second;
pq.pop();
if(vis[u]){
continue;
}
vis[u] = true;
for(auto it : adj[u]){
int v = it.first;
ll w = it.second;
if(vis[v]) continue;
dist[v] = min(dist[v], d_u+w);
pq.push({dist[v], v});
}
}
return dist;
}
void solve(){
int n, m;
cin >> n >> m;
int S, T, U, V;
cin >> S >> T;
cin >> U >> V;
vector<vector<pair<ll, ll>>> adj(n+1), adj1, adj2;
for(int i = 1; i <= m; i++){
int u, v, w;
cin >> u >> v >> w;
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
adj1 = adj;
adj2 = adj;
vector<ll> ds = dijkstra(S, adj), dt = dijkstra(T, adj);
for(int u = 1; u <= n; u++){
if(ds[u]+dt[u] != ds[T]) continue;
for(auto it : adj[u]){
int v = it.first;
ll w = it.second;
if(ds[v]+dt[v] != ds[T]) continue;
if(ds[u]+w == ds[v]){
adj1[u].push_back({v, 0});
}
if(dt[u]+w == dt[v]){
adj2[u].push_back({v, 0});
}
}
}
vector<ll> du1 = dijkstra(U, adj1), du2 = dijkstra(U, adj2), dv = dijkstra(V, adj);
ll ans = INF;
ans = min(du1[V], du2[V]);
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("main.inp", "r", stdin);
freopen("main.out", "w", stdout);
solve();
}
Compilation message (stderr)
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:69:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | freopen("main.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:70:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | freopen("main.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... |