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>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=3e5+5;
vector<pair<int,int>>v[N];
set<int>st[N];
int dist[N];
int tmp[N];
int par[N];
bool vis[N];
vector<pair<int,int>>vc;
signed main(){
int n,m,s,t,x,y;
cin>>n>>m>>s>>t>>x>>y;
for(int i=0;i<m;i++){
int a,b,c;
cin>>a>>b>>c;
v[a].pb({b,c});
v[b].pb({a,c});
}
for(int i=1;i<=n;i++){
dist[i]=1e16;
}
priority_queue<pair<int,int>>q;
q.push({0,s});
par[s]=s;
dist[s]=0;
vis[s]=1;
while(!q.empty()){
int w=-q.top().ff;
int a=q.top().ss;
q.pop();
if(dist[a]<w)continue;
for(auto p:v[a]){
int b=p.ff;
int c=p.ss;
st[b].clear();
st[b]=st[a];
st[b].insert(b);
if(dist[a]+c<=dist[b]){
dist[b]=dist[a]+c;
par[b]=a;
q.push({-dist[b],b});
}
}
}
for(auto a:st[t]){
vis[a]=1;
}
while(t!=s){
v[t].pb({par[t],0});
v[par[t]].pb({t,0});
t=par[t];
}
for(int i=1;i<=n;i++){
dist[i]=1e16;
}
s=y;
q.push({0,s});
par[s]=s;
dist[s]=0;
while(!q.empty()){
int w=-q.top().ff;
int a=q.top().ss;
q.pop();
if(dist[a]<w)continue;
for(auto p:v[a]){
int b=p.ff;
int c=p.ss;
if(dist[a]+c<dist[b]){
dist[b]=dist[a]+c;
par[b]=a;
q.push({-dist[b],b});
}
}
}
int ans=INT_MAX;
for(int i=1;i<=n;i++){
if(vis[i]){
ans=min(ans,dist[i]);
}
}
cout<<ans;
}
# | 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... |