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 ff first
#define ss second
using namespace std;
ll n,m,s,t,u,v,x,y,z,i,dis[100001];
vector<pair<ll,ll>> g[100001];
priority_queue<pair<ll,ll>> q;
map<pair<ll,ll>,bool> mp;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m >> s >> t >> u >> v;
for(i=1;i<=m;i++){
cin >> x >> y >> z;
g[x].push_back({y,z});
g[y].push_back({x,z});
}
memset(dis,-1,sizeof dis);
q.push({0,s});
while(!q.empty()){
z=q.top().ff;
x=q.top().ss;
q.pop();
if(dis[x]!=-1) continue;
dis[x]=-z;
for(pair<ll,ll> i:g[x]){
if(dis[i.ff]==-1) q.push({z-i.ss,i.ff});
}
}
x=t;
while(x!=s){
for(pair<ll,ll> i:g[x]){
if(dis[x]==dis[i.ff]+i.ss){
mp[{x,i.ff}]=1;
mp[{i.ff,x}]=1;
x=i.ff;
break;
}
}
}
memset(dis,-1,sizeof dis);
q.push({0,u});
while(!q.empty()){
z=q.top().ff;
x=q.top().ss;
q.pop();
if(dis[x]!=-1) continue;
dis[x]=-z;
for(pair<ll,ll> i:g[x]){
if(dis[i.ff]==-1){
if(mp[{x,i.ff}]) q.push({z,i.ff});
else q.push({z-i.ss,i.ff});
}
}
}
cout << dis[v];
}
# | 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... |