結果

問題 No.160 最短経路のうち辞書順最小
ユーザー tails
提出日時 2015-03-02 01:28:48
言語 Perl
(5.40.0)
結果
RE  
実行時間 -
コード長 459 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 6,688 KB
実行使用メモリ 14,208 KB
最終ジャッジ日時 2024-06-24 00:55:09
合計ジャッジ時間 2,291 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23 RE * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
Name "main::time" used only once: possible typo at Main.pl line 11.
Name "main::m" used only once: possible typo at Main.pl line 1.
Main.pl syntax OK

ソースコード

diff #

($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){
    die if ++$time>1000;
    #@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);
0