const
maxp=10000;
var
p,c,s,t:longint;
a,b:array[1..maxp,0..maxp]of longint;
d:array[1..maxp]of longint;
v:array[1..maxp]of boolean;
dist:array[1..maxp]of longint;
head,tail:longint;
procedure init;
var
i,x,y,z:longint;
begin
read(p,c);
for i:=1 to c do
begin
readln(x,y,z);
inc(b[x,0]);b[x,b[x,0]]:=y;a[x,y]:=z;
inc(b[y,0]);b[y,b[x,0]]:=x;a[y,x]:=z;{wu xiang zhuan yong}
end;
readln(s,t);
end;
procedure spaf(s:longint);
var
i,j,now,sum:longint;
begin
fillchar(d,sizeof(d),0);
fillchar(v,sizeof(v),false);
for j:=1 to p do dist[j]:=maxlongint;
dist[s]:=0; v[s]:=true;d[1]:=s;
head:=1;tail:=1;
while head<=tail do
begin
now:=d[head];
for i:=1 to b[now,0]do
if dist[b[now,i]]>dist[now]+a[now,b[now,i]] then
begin
dist[b[now,i]]:=dist[now+a[now,b[now,i]]];
if not v[b[now,i]] then
begin
inc(tail);
d[tail]:=b[now,i];
v[b[now,i]]:=true;
end;end;end;end;
procedure print;
begin
writeln(dist[t]);
end;
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
init;
spaf(s);
print;
close(input);
close(output);
end.
const maxp=10000;
var p,c,s,t:longint;
a,b:array[1..maxp,0..maxp]of longint;
d:array[1..maxp]of integer;
v:array[1..maxp]of boolean;
dist:array[1..maxp]of longint;
head,tail:longint;
procedure init;
var i,x,y,z:longint;
begin
read(p,c); for i:=1 to c do
begin
readln(x,y,z);
inc(b[x,0]);b[x,b[x,0]]:=y;a[x,y]:=z;
inc(b[y,0]);b[y,b[y,0]]:=x;a[y,x]:=z;
end;
readln(s,t);
end;
procedure spfa(s:longint);
var i,j,now,sum:longint;
begin
fillchar(d,sizeof(d),0);
fillchar(v,sizeof(v),false);
for j:=1 to p do dist[j]:=maxlongint;
dist[s]:=0; v[s]:=true; d[1]:=s;
head:=1; tail:=1; while head<=tail do
begin
now:=d[head];
for i:=1 to b[now,0] do
if dist[b[now,i]]>dist[now]+a[now,b[now,i]] then
begin
dist[b[now,i]]:=dist[now]+a[now,b[now,i]];
if not v[b[now,i]] then
begin
inc(tail);
d[tail]:=b[now,i];
v[b[now,i]]:=true; end; end;
v[now]:=false;
inc(head);
end; end;
procedure print;
begin
writeln(dist[t]);
end;
begin
init;
spfa(s);
print;
end.
program p111;
const
maxp=10000;
var
p,c,s,t:longint;
a,b:array[1..maxp,0..maxp] of longint;
d,time:array[1..maxp] of integer;
v:array[1..maxp] of boolean;
dist:array[1..maxp] of longint;
head,tail:longint;
procedure init;
var
i,x,y,z:longint;
begin
read(p,c);
for i:=1 to c do
begin
readln(x,y,z);
inc(b[x,0]);b[x,b[x,0]]:=y;a[x,y]:=z;
end;
readln(s,t);
end;
procedure spfa(s:longint);
var
i,j,now,sum:longint;
begin
fillchar(d,sizeof(d),0);
fillchar(v,sizeof(v),false);
for j:=1 to p do dist[j]:=maxlongint;
dist[s]:=0; v[s]:=true; d[1]:=s;
head:=1; tail:=1;
while head<=tail do
begin
now:=d[head];
for i:=1 to b[now,0] do
if dist[b[now,i]]>dist[now]+a[now,b[now,i]] then
begin
dist[b[now,i]]:=dist[now]+a[now,b[now,i]];
if not v[b[now,i]] then
begin
inc[tail]:=b[now,i];
v[b[now,i]]:=true;
inc(time[b[now,i]]);
if time[b[now,i]]>p then begin write('no'); halt; end;
end;
end;
v[now]:=false;
inc(head);
end;
end;
procedure print;
begin
init;
safa(s);
print;
end.