($n,$m,$s,$g)=<>=~/\d+/g; for(<>){ ($a,$b,$c)=/\d+/g; $c{$a,$b}=$c{$b,$a}=$c; } #print"a\n"; $v[$g]=1; push@a,$g; while(@a){ #@a=sort{$v[$a]-$v[$b]}@a; $a=shift@a; for$b(0..$n-1){ if($c=$c{$a,$b}){ if($v[$b]==0||$v[$b]>$v[$a]+$c||$v[$b]==$v[$a]+$c&&$p[$b]>$a) { $v[$b]=$v[$a]+$c; $p[$b]=$a; push@a,$b; } } } } #print"b\n"; print $s; $a=$s; do{ $a=$p[$a]; print" $a"; }while($a!=$g);