This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//In His Name
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
#define F first
#define S second
#define pb push_back
#define bug(x) cout << "Ah shit , here we go again : " << x <<endl
#define all(x) x.begin() , x.end()
#define ceil(x,y) x/y + min(1ll,x%y)
const int maxn = 2e5 + 10, MOD = 1e9 + 7;
const ll INF = 1e18;
int n , m , s , t , u , v ,par[maxn] , dis[maxn];
vector<pli> adj[maxn];
vector<int> path;
void dijkstra(int root){
fill(dis , dis+n+1 , INF);
dis[root] = 0;
set<pli> s;
s.insert({0,root});
while(!s.empty()){
int a = (*s.begin()).S;
s.erase(s.begin());
for(pii i : adj[a]){
if(dis[i.S] > dis[a] + i.F){
s.erase({dis[i.S] , i.S});
dis[i.S] = dis[a] + i.F;
s.insert({dis[i.S] , i.S});
par[i.S] = a;
}
}
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin >> n >> m >> s >> t >> u >> v;
for(int i = 1 ; i <= m ; i ++){
int a , b , w;
cin >> a >> b >> w;
adj[a].pb({w , b});
adj[b].pb({w , a});
}
dijkstra(s);
int x = par[t];
while(x != par[s]){
path.pb(x);
x = par[x];
}
dijkstra(v);
int ans = INF;
for(int i : path) ans = min(ans, dis[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... |