#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ar array
const int MOD = 1e9 + 7,INF = 1e18, N = 2e5 + 5;
/*
5 2
1 2 2
2 3 2
3 4 2
4 5 2
*/
void solve(){
	int n , m;
	cin >> n >> m;
	int s , t , u , v;
	cin >> s >> t >> u >> v;
	vector <vector <pair<int,int>>> g(n + 1);
	
	for(int i = 0;i < m;i++){
		int a , b , c;
		cin >> a >> b >> c;
		
		g[a].pb({b , c});
		g[b].pb({a , c});
	}
	vector <int> path(n + 1);
{
	vector <vector <int>> p(n + 1);
	vector <int> cnt(n + 1, INF);
	cnt[s] = 0;
	p[s].pb(-1);
	priority_queue <int> q;
	
	q.push(s);
	
	while(!q.empty()){
		int x = q.top();
		q.pop();
		// cout<<x<<endl;
		for(auto [i , c] : g[x]){
			if(cnt[i] > cnt[x] + c){
				// cout<<c<<"c " << endl;
				cnt[i] = cnt[x] + c;
				p[i].clear();
				p[i].pb(x);
				q.push(i);
			}
			else if(cnt[i] == cnt[x] + c){
				p[i].pb(x);
			}
		}
	}
	
	// for(int i = 1;i <= n;i++){
		// cout<<cnt[i]<<' ';
	// }
	// cout<<endl;
	priority_queue <int> cntp;
	cntp.push(t);
	
	
	while(!cntp.empty()){
		int x = cntp.top();
		cntp.pop();
		
		for(int i : p[x]){
			if(i != -1 && !path[i]){
				path[i] = 1;
				cntp.push(i);
			}
		}
	}
	// for(int i = 0;i <= n;i++){
		// cout<<path[i]<<' ';
	// }
	// cout<<endl;
}
	queue <int> q;
	q.push(v);
	vector <int> cnt(n + 1,INF);
	cnt[v] = 0;
	
	while(!q.empty()){
		int x = q.front();
		q.pop();
		
		for(auto [i , c] : g[x]){
			if(cnt[i] > cnt[x] + c){
				cnt[i] = cnt[x] + c;
				q.push(i);
			}
		}
	}
	
	int ans = INF;
	
	for(int i = 1;i <= n;i++){
		if(path[i]){
			ans = min(ans , cnt[i]);
		}
	}
	cout<<ans<<endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int ti = 1;
    while (ti--) {
		solve();
    }
}
| # | 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... |