<?php
SUBWAY => 'едешь на метро',
FOOT => 'идешь пешком',
BUS => 'едешь на автобусе'
);
$startPoint = 'pet'; // Петроградская
$endPoint = 'nov'; // Новая Голландия
'pet' => 'ст. м. Петроградская',
'chk' => 'ст. м. Чкаловская',
'gor' => 'ст. м. Горьковская',
'spo' => 'ст. м. Спортивная',
'vas' => 'ст. м. Василеостровская',
'kre' => 'Петропавловская крепость',
'let' => 'Летний сад',
'dvo' => 'Дворцовая площадь',
'isa' => 'Исакиевский собор',
'nov' => 'Новая Голландия',
'ras' => 'Дом Раскольникова',
'gos' => 'Гостиный Двор',
'sen' => 'Сенная Площадь',
'vla' => 'ст. м. Владимирская',
'vit' => 'Витебский вокзал',
'teh' => 'Технологический Институт'
);
/* Чтобы не писать много раз array('time' => ..., 'by' => ...), используем функцию.
«canGet» переводится как «можно попасть» */
function canGet($time, $byWhat) {
return array('time' => $time, 'by' => $byWhat); }
'chk' => canGet(10, BUS),
'gor' => canGet(3, SUBWAY)
),
'pet' => canGet(10, BUS),
'spo' => canGet(3, SUBWAY)
),
'pet' => canGet(3, BUS),
'kre' => canGet(5, FOOT),
'gos' => canGet(6, SUBWAY)
),
'chk' => canGet(3, SUBWAY),
'vas' => canGet(10, BUS),
'sen' => canGet(7, SUBWAY)
),
'spo' => canGet(10, BUS),
'gos' => canGet(7, SUBWAY),
'nov' => canGet(11, FOOT)
),
'gor' => canGet(5, FOOT)
),
'dvo' => canGet(6, FOOT),
'gos' => canGet(7, FOOT)
),
'isa' => canGet(6, FOOT),
'gos' => canGet(6, FOOT),
'let' => canGet(6, FOOT)
),
'dvo' => canGet(6, FOOT),
'nov' => canGet(5, FOOT)
),
'vas' => canGet(11, FOOT),
'isa' => canGet(5, FOOT),
'ras' => canGet(7, BUS)
),
'nov' => canGet(7, BUS),
'sen' => canGet(3, FOOT)
),
'vas' => canGet(7, SUBWAY),
'sen' => canGet(3, SUBWAY),
'dvo' => canGet(6, FOOT),
'gor' => canGet(6, SUBWAY),
'let' => canGet(7, FOOT),
'vla' => canGet(7, FOOT)
),
'ras' => canGet(3, FOOT),
'spo' => canGet(7, SUBWAY),
'gos' => canGet(3, SUBWAY),
'vla' => canGet(4, SUBWAY),
'vit' => canGet(2, SUBWAY),
'teh' => canGet(3, SUBWAY)
),
'sen' => canGet(4, SUBWAY),
'gos' => canGet(7, FOOT),
'vit' => canGet(3, SUBWAY)
),
'sen' => canGet(2, SUBWAY),
'teh' => canGet(2, SUBWAY),
'vla' => canGet(3, SUBWAY)
),
'sen' => canGet(3, SUBWAY),
'vit' => canGet(2, SUBWAY)
)
);
function makeStep($paths, $pathDone, $time, $point, $target){
$time += $paths[$point][$target]['time'];
} else {
foreach($paths[$point] as $key => $value){
makeStep($paths, $pathDone, $time, $paths[$key], $target);
}
}
$result = [
'path' => $pathDone,
'time' => $time,
];
return $result;
}
$pathDone = [];
$time = 0;
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKbWJfaW50ZXJuYWxfZW5jb2RpbmcoJ3V0Zi04Jyk7CgpkZWZpbmUoJ1NVQldBWScsICdzdWInKTsKZGVmaW5lKCdGT09UJywgJ2Zvb3QnKTsKZGVmaW5lKCdCVVMnLCAnYnVzJyk7CgokdHJhbnNwb3J0TmFtZSA9IGFycmF5KAogICAgU1VCV0FZICA9PiAgJ9C10LTQtdGI0Ywg0L3QsCDQvNC10YLRgNC+JywKICAgIEZPT1QgICAgPT4gICfQuNC00LXRiNGMINC/0LXRiNC60L7QvCcsCiAgICBCVVMgICAgID0+ICAn0LXQtNC10YjRjCDQvdCwINCw0LLRgtC+0LHRg9GB0LUnCik7Cgokc3RhcnRQb2ludCA9ICdwZXQnOyAvLyDQn9C10YLRgNC+0LPRgNCw0LTRgdC60LDRjwokZW5kUG9pbnQgPSAnbm92JzsgLy8g0J3QvtCy0LDRjyDQk9C+0LvQu9Cw0L3QtNC40Y8KCiRwb2ludE5hbWVzID0gYXJyYXkoCiAgICAncGV0JyAgID0+ICAn0YHRgi4g0LwuINCf0LXRg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0LHRiyDQvdC1INC/0LjRgdCw0YLRjCDQvNC90L7Qs9C+INGA0LDQtyBhcnJheSgndGltZScgPT4gLi4uLCAnYnknID0+IC4uLiksINC40YHQv9C+0LvRjNC30YPQtdC8INGE0YPQvdC60YbQuNGOLgogICAgwqtjYW5HZXTCuyDQv9C10YDQtdCy0L7QtNC40YLRgdGPINC60LDQuiDCq9C80L7QttC90L4g0L/QvtC/0LDRgdGC0YzCuyAqLwpmdW5jdGlvbiBjYW5HZXQoJHRpbWUsICRieVdoYXQpIHsKICAgIHJldHVybiBhcnJheSgndGltZScgPT4gICR0aW1lLCAnYnknID0+ICRieVdoYXQpOwp9CgokcGF0aHMgPSBhcnJheSgKICAgICdwZXQnICAgPT4gIGFycmF5KAogICAgICAgICdjaGsnICAgPT4gIGNhbkdldCgxMCwgQlVTKSwKICAgICAgICAnZ29yJyAgID0+ICBjYW5HZXQoMywgU1VCV0FZKQogICAgKSwKCiAgICAnY2hrJyAgID0+ICBhcnJheSgKICAgICAgICAncGV0JyAgID0+ICBjYW5HZXQoMTAsIEJVUyksCiAgICAgICAgJ3NwbycgICA9PiAgY2FuR2V0KDMsIFNVQldBWSkKICAgICksCgogICAgJ2dvcicgICA9PiAgYXJyYXkoCiAgICAgICAgJ3BldCcgICA9PiAgY2FuR2V0KDMsIEJVUyksCiAgICAgICAgJ2tyZScgICA9PiAgY2FuR2V0KDUsIEZPT1QpLAogICAgICAgICdnb3MnICAgPT4gIGNhbkdldCg2LCBTVUJXQVkpCiAgICApLAoKICAgICdzcG8nICAgPT4gIGFycmF5KAogICAgICAgICdjaGsnICAgPT4gIGNhbkdldCgzLCBTVUJXQVkpLAogICAgICAgICd2YXMnICAgPT4gIGNhbkdldCgxMCwgQlVTKSwKICAgICAgICAnc2VuJyAgID0+ICBjYW5HZXQoNywgU1VCV0FZKQogICAgKSwKCiAgICAndmFzJyAgID0+ICBhcnJheSgKICAgICAgICAnc3BvJyAgID0+ICBjYW5HZXQoMTAsIEJVUyksCiAgICAgICAgJ2dvcycgICA9PiAgY2FuR2V0KDcsIFNVQldBWSksCiAgICAgICAgJ25vdicgICA9PiAgY2FuR2V0KDExLCBGT09UKQogICAgKSwKCiAgICAna3JlJyAgID0+ICBhcnJheSgKICAgICAgICAnZ29yJyAgID0+ICBjYW5HZXQoNSwgRk9PVCkKICAgICksCgogICAgJ2xldCcgICA9PiAgYXJyYXkoCiAgICAgICAgJ2R2bycgICA9PiAgY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdnb3MnICAgPT4gIGNhbkdldCg3LCBGT09UKQogICAgKSwKCiAgICAnZHZvJyAgID0+ICBhcnJheSgKICAgICAgICAnaXNhJyAgID0+ICBjYW5HZXQoNiwgRk9PVCksCiAgICAgICAgJ2dvcycgICA9PiAgY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdsZXQnICAgPT4gIGNhbkdldCg2LCBGT09UKQogICAgKSwKCiAgICAnaXNhJyAgID0+ICBhcnJheSgKICAgICAgICAnZHZvJyAgID0+ICBjYW5HZXQoNiwgRk9PVCksCiAgICAgICAgJ25vdicgICA9PiAgY2FuR2V0KDUsIEZPT1QpCiAgICApLAoKICAgICdub3YnICAgPT4gIGFycmF5KAogICAgICAgICd2YXMnICAgPT4gIGNhbkdldCgxMSwgRk9PVCksCiAgICAgICAgJ2lzYScgICA9PiAgY2FuR2V0KDUsIEZPT1QpLAogICAgICAgICdyYXMnICAgPT4gIGNhbkdldCg3LCBCVVMpCiAgICApLAoKICAgICdyYXMnICAgPT4gIGFycmF5KAogICAgICAgICdub3YnICAgPT4gIGNhbkdldCg3LCBCVVMpLAogICAgICAgICdzZW4nICAgPT4gIGNhbkdldCgzLCBGT09UKQogICAgKSwKCiAgICAnZ29zJyAgID0+ICBhcnJheSgKICAgICAgICAndmFzJyAgID0+ICBjYW5HZXQoNywgU1VCV0FZKSwKICAgICAgICAnc2VuJyAgID0+ICBjYW5HZXQoMywgU1VCV0FZKSwKICAgICAgICAnZHZvJyAgID0+ICBjYW5HZXQoNiwgRk9PVCksCiAgICAgICAgJ2dvcicgICA9PiAgY2FuR2V0KDYsIFNVQldBWSksCiAgICAgICAgJ2xldCcgICA9PiAgY2FuR2V0KDcsIEZPT1QpLAogICAgICAgICd2bGEnICAgPT4gIGNhbkdldCg3LCBGT09UKQogICAgKSwKCiAgICAnc2VuJyAgID0+ICBhcnJheSgKICAgICAgICAncmFzJyAgID0+ICBjYW5HZXQoMywgRk9PVCksCiAgICAgICAgJ3NwbycgICA9PiAgY2FuR2V0KDcsIFNVQldBWSksCiAgICAgICAgJ2dvcycgICA9PiAgY2FuR2V0KDMsIFNVQldBWSksCiAgICAgICAgJ3ZsYScgICA9PiAgY2FuR2V0KDQsIFNVQldBWSksCiAgICAgICAgJ3ZpdCcgICA9PiAgY2FuR2V0KDIsIFNVQldBWSksCiAgICAgICAgJ3RlaCcgICA9PiAgY2FuR2V0KDMsIFNVQldBWSkKICAgICksCgogICAgJ3ZsYScgICA9PiAgYXJyYXkoCiAgICAgICAgJ3NlbicgICA9PiAgY2FuR2V0KDQsIFNVQldBWSksCiAgICAgICAgJ2dvcycgICA9PiAgY2FuR2V0KDcsIEZPT1QpLAogICAgICAgICd2aXQnICAgPT4gIGNhbkdldCgzLCBTVUJXQVkpCiAgICApLAoKICAgICd2aXQnICAgPT4gIGFycmF5KAogICAgICAgICdzZW4nICAgPT4gIGNhbkdldCgyLCBTVUJXQVkpLAogICAgICAgICd0ZWgnICAgPT4gIGNhbkdldCgyLCBTVUJXQVkpLAogICAgICAgICd2bGEnICAgPT4gIGNhbkdldCgzLCBTVUJXQVkpCiAgICApLAoKICAgICd0ZWgnICAgPT4gIGFycmF5KAogICAgICAgICdzZW4nICAgPT4gIGNhbkdldCgzLCBTVUJXQVkpLAogICAgICAgICd2aXQnICAgPT4gIGNhbkdldCgyLCBTVUJXQVkpCiAgICApCik7CgpmdW5jdGlvbiBtYWtlU3RlcCgkcGF0aHMsICRwYXRoRG9uZSwgJHRpbWUsICRwb2ludCwgJHRhcmdldCl7CgogICAgaWYgKGFycmF5X2tleV9leGlzdHMoJHRhcmdldCwgJHBhdGhzWyRwb2ludF0pKXsKICAgICAgICBhcnJheV9wdXNoKCRwYXRoRG9uZSwgJHRhcmdldCk7CiAgICAgICAgJHRpbWUgKz0gJHBhdGhzWyRwb2ludF1bJHRhcmdldF1bJ3RpbWUnXTsKCiAgICB9IGVsc2UgewogICAgICAgIGZvcmVhY2goJHBhdGhzWyRwb2ludF0gYXMgJGtleSA9PiAkdmFsdWUpewogICAgICAgICAgICBtYWtlU3RlcCgkcGF0aHMsICRwYXRoRG9uZSwgJHRpbWUsICRwYXRoc1ska2V5XSwgJHRhcmdldCk7CiAgICAgICAgfQoKICAgIH0KCiAgICAkcmVzdWx0ID0gWwogICAgICAgICdwYXRoJyA9PiAkcGF0aERvbmUsCiAgICAgICAgJ3RpbWUnID0+ICR0aW1lLAogICAgXTsKICAgIHJldHVybiAgJHJlc3VsdDsKfQoKJHBhdGhEb25lID0gW107CiR0aW1lID0gMDs=