Program ongbangau;
const fi='LOVE.INP';
      fo='LOVE.OUT';
      nmax=Trunc(1e3);

Var a: array[1..nmax, 1..nmax] of longint;
    d, SD, TD: array[1..nmax] of longint;
    ch: array[1..nmax] of Boolean;
    n, m, u, v, s, t, res: longint;
    f: text;

Procedure doc;
Var i,x, y, z: longint;
Begin
     assign(f,fi); reset(f);
     read(f, n, m, s, t);
     for i:=1 to m do
        begin
           read(f, x, y, z);
           a[x,y]:=z;
           a[y,x]:=z;
        end;
     close(f);
end;
Procedure Dtra(s, t: longint);
Var i,j, u, v, min: longint;
Begin
    For i:=1 To n Do
        Begin
            D[i]:=MaxInt;
            Ch[i]:=False;
        End;

    D[s]:=0;
    For i:=1 To n Do
       Begin

           Min:=MaxInt;
           For j:=1 To n Do
               If (D[j]< Min) And (Ch[j]=False) Then
                  Begin
                       Min:=D[j];
                       u:=j;
                  End;

            Ch[u]:=True;

            //If u = t Then Exit;

            For v:=1 To n Do
                If (ch[v]=false) and (a[u,v]<>0) And (d[v]>d[u]+a[u,v]) Then

                       D[v]:=D[u]+A[u,v];
           End;
End;

Begin
    Doc;
    DTra(s,T);
    Assign(f, fo);
    Rewrite(f);
    Write(f,d[t]);
    close(f);
End.
