#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> PII;

const int N = 400100;

int C,P,PB,PA1,PA2;
int e[N],w[N],ne[N],h[N],idx;
int d[N];
bool str[N];

void add(int a,int b,int c)
{
	e[idx]=b,w[idx]=c,ne[idx]=h[a],h[a]=idx++;
}

int dijkstra(int x,int n)
{
	memset(d,0x3f,sizeof d);
	memset(str,false,sizeof str);
	priority_queue<PII,vector<PII>,greater<PII> > heap;
	d[x]=0;
	heap.push({0,x});
	
	while(heap.size())
	{
		PII t=heap.top();
		heap.pop();
		
		int ver=t.second;
		
        if(str[ver]) continue;
        str[ver]=true;
        
		for(int i=h[ver];i!=-1;i=ne[i])
		{
			int j=e[i];
			if(d[j]>d[ver]+w[i])
			{
				d[j]=d[ver]+w[i];
                heap.push({d[j],j});
			}
		}
	}
	return d[n];
}

int main()
{
	cin>>C>>P>>PB>>PA1>>PA2;
	memset(h,-1,sizeof h);
	
	while(C--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		add(a,b,c),add(b,a,c);
	}
	
	int res=dijkstra(PB,PA1)+dijkstra(PA1,PA2);
	int ans=dijkstra(PB,PA2)+dijkstra(PA2,PA1);
	
	cout<<min(res,ans)<<'\n';
	return 0;
}