$direct = $input->lines->mapAssoc(fn ($i, $line) => [
explode(")", $line)[1] => explode(")", $line)[0]
]);
$paths = [];
foreach ($direct as $to=>$from) {
$paths[$to] ??= [];
do $paths[$to][] = $from;
while ($from = $direct[$from] ?? false);
}
// ==================================================
// > PART 1
// ==================================================
$solution_1 = count(array_merge(...array_values($paths)));
// ==================================================
// > PART 2
// ==================================================
$common = set(array_merge($paths["YOU"], $paths["SAN"]))->duplicates()->first();
$solution_2 = array_search($common, $paths["YOU"]) + array_search($common, $paths["SAN"]);