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 ll long long
#define ldb long double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,int>
using namespace std;
const int maxn = 1e5 + 5;
ll dist[maxn][3],D = 0,dp[maxn];
bool mark[maxn];
vector <vector<pir>> vec(maxn);
void input(int n,int m){
while (m--){
int u,v,w;
cin >> u >> v >> w;
vec[u].push_back({v,w});
vec[v].push_back({u,w});
}
}
void dijkstra(int source,int n,int st){
for (int i = 1 ; i <= n ; i++) mark[i] = 0;
priority_queue <pirll,vector<pirll>,greater<pirll>> pq;
pq.push({0,source});
while (pq.size()){
pirll t = pq.top();
pq.pop();
int u = t.se;ll w = t.fi;
if (mark[u]) continue;
mark[u] = 1;
dist[u][st] = w;
for (pir v : vec[u])
if (!mark[v.fi])
pq.push({v.se + w,v.fi});
}
D = dist[source][0];
}
void solve(int source,int n){
for (int i = 1 ; i <= n ; i++)
mark[i] = 0;
priority_queue <pirll,vector<pirll>,greater<pirll>> pq;
pq.push({0,source});
while (pq.size()){
pirll t = pq.top();
pq.pop();
int u = t.se;ll w = t.fi;
if (mark[u]) continue;
mark[u] = 1;
dp[u] = w;
for (pir node : vec[u])
if (!mark[node.fi]){
int v = node.fi,e = node.se;
if (dist[u][0] + e + dist[v][1] == D || dist[u][1] + e + dist[v][0] == D)
pq.push({w,v});
else
pq.push({w + e,v});
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
//freopen("commuterpass.inp","r",stdin);
// freopen("commuterpass.out","w",stdout);
int n,m,S,T,U,V;
cin >> n >> m >> S >> T >> U >> V;
input(n,m);
dijkstra(S,n,0);
dijkstra(T,n,1);
solve(U,n);
cout << dp[V];
return 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... |