<?php 'visited' => false, // были ли в вершине: false = небыли, true = были 'shortest_path' => INF, // наименьшая длина пути до вершины INF = бесконечно. ) ), 'visited' => false, 'shortest_path' => INF, ) ), 'visited' => false, 'shortest_path' => INF, ) ), 'visited' => false, 'shortest_path' => INF, ) ), 'visited' => false, 'shortest_path' => INF, ) ), 'visited' => false, 'shortest_path' => INF, ) ) ); $start_point = one; $end_point = six; function asd($paths,$start_point,$end_point) { $paths[$start_point][shortest_path] = 0; // делаем длинну пути стартовой точки = 0 while ($paths[$end_point][visited] == false) { // циклим пока точка до которой мы идем не станет true $paths[$start_point][visited] = true; // ставим посещение true foreach ($paths[$start_point][neighbors] as $name => $array_path_trnnames) { // смотрим соседей вершины и длинну пути и присваем if длина пути+пройденый путь меньше чем есть foreach ($array_path_trnnames as $path_length => $transport_name) { if ($paths[$name][visited] == false) { if ($path_length+$paths[$start_point][shortest_path]< $paths[$name][shortest_path]) { $paths[$name][shortest_path] = $path_length+$paths[$start_point][shortest_path]; } } } } $j = INF; foreach ($paths as $name => $value) { // делаем старт поинт вершину с наименьшем пути if ($paths[$name][visited] == false ) { if ($paths[$name][shortest_path]< $j) { $j = $paths[$name][shortest_path]; $start_point = $name; } } } $array[] = $start_point." \n"; // массив со всеми пройдеными точками } return $array; } $array = asd($paths,$start_point,$end_point); //var_export ($array) ;
Standard input is empty
array ( 0 => 'two ', 1 => 'three ', 2 => 'fow ', 3 => 'five ', 4 => 'six ', 5 => 'six ', )
PHP Notice: Use of undefined constant BUS - assumed 'BUS' in /home/05CCSO/prog.php on line 8 PHP Notice: Use of undefined constant SUBWAY - assumed 'SUBWAY' in /home/05CCSO/prog.php on line 9 PHP Notice: Use of undefined constant BUS - assumed 'BUS' in /home/05CCSO/prog.php on line 10 PHP Notice: Use of undefined constant BUS - assumed 'BUS' in /home/05CCSO/prog.php on line 18 PHP Notice: Use of undefined constant BUS - assumed 'BUS' in /home/05CCSO/prog.php on line 26 PHP Notice: Use of undefined constant FOOT - assumed 'FOOT' in /home/05CCSO/prog.php on line 27 PHP Notice: Use of undefined constant BUS - assumed 'BUS' in /home/05CCSO/prog.php on line 35 PHP Notice: Use of undefined constant BUS - assumed 'BUS' in /home/05CCSO/prog.php on line 36 PHP Notice: Use of undefined constant BUS - assumed 'BUS' in /home/05CCSO/prog.php on line 44 PHP Notice: Use of undefined constant FOOT - assumed 'FOOT' in /home/05CCSO/prog.php on line 45 PHP Notice: Use of undefined constant BUS - assumed 'BUS' in /home/05CCSO/prog.php on line 53 PHP Notice: Use of undefined constant FOOT - assumed 'FOOT' in /home/05CCSO/prog.php on line 54 PHP Notice: Use of undefined constant one - assumed 'one' in /home/05CCSO/prog.php on line 59 PHP Notice: Use of undefined constant six - assumed 'six' in /home/05CCSO/prog.php on line 60 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 65 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 66 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 67 PHP Notice: Use of undefined constant neighbors - assumed 'neighbors' in /home/05CCSO/prog.php on line 68 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 70 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 71 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 71 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 72 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 72 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 70 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 71 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 71 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 72 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 72 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 70 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 71 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 71 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 72 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 72 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 80 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 81 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 80 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 80 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 80 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 80 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 66 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 67 PHP Notice: Use of undefined constant neighbors - assumed 'neighbors' in /home/05CCSO/prog.php on line 68 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 70 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 80 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 81 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 80 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 80 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 80 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 66 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 67 PHP Notice: Use of undefined constant neighbors - assumed 'neighbors' in /home/05CCSO/prog.php on line 68 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 70 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 70 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 71 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 71 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 72 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 72 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 80 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 81 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 80 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 80 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 66 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 67 PHP Notice: Use of undefined constant neighbors - assumed 'neighbors' in /home/05CCSO/prog.php on line 68 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 70 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 70 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 71 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 71 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 72 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 72 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 80 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 81 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 80 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 66 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 67 PHP Notice: Use of undefined constant neighbors - assumed 'neighbors' in /home/05CCSO/prog.php on line 68 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 70 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 70 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 71 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 71 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 72 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 72 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 80 PHP Notice: Use of undefined constant shortest_path - assumed 'shortest_path' in /home/05CCSO/prog.php on line 81 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 66 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 67 PHP Notice: Use of undefined constant neighbors - assumed 'neighbors' in /home/05CCSO/prog.php on line 68 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 70 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 70 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 79 PHP Notice: Use of undefined constant visited - assumed 'visited' in /home/05CCSO/prog.php on line 66