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 fr first
#define sc second
#define ll long long int
const int mxn=1e5+5;
ll n,m,dis[2][mxn],s,t,u,v,par[2][mxn],ans=1e18;
vector<pair<int,int> >yal[mxn];
set<pair<ll,ll> >st;
void dij(int r,int f){
for(int i=1;i<=n;i++){
dis[f][i]=(i==r)?0:1e18;
st.insert({dis[f][i],i});
}
while(st.size()){
auto x=*st.begin();
st.erase({x.fr,x.sc});
//cout<<x.sc<<" "<<par[f][x.sc]<<endl;
for(auto i:yal[x.sc]){
if(dis[f][i.fr]>x.fr+i.sc){
st.erase({dis[f][i.fr],i.fr});
dis[f][i.fr]=x.fr+i.sc;
st.insert({dis[f][i.fr],i.fr});
par[f][i.fr]=x.sc;
}
}
}
}
int main(){
cin>>n>>m;
cin>>s>>t>>u>>v;
for(int i=1;i<=m;i++){
int x,y,w;
cin>>x>>y>>w;
yal[x].push_back({y,w});
yal[y].push_back({x,w});
}
dij(s,0);
//cout<<endl;
dij(v,1);
for(int x=t;x!=0;x=par[0][x]){
//cout<<x<<" ";
ans=min(ans,dis[1][x]);
}
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... |