enqueue($i); } } $ans = 0; $ans2 = []; //echo "------------".PHP_EOL; while($q->count() > 0){ $i = $q->dequeue(); // echo $i."=".($sw[$i] ? "on" : "off"); if($sw[$i]) { $ans++; $ans2[] = $i; } if(!isset($route[$i])) { // echo PHP_EOL; continue; } foreach($route[$i] as $j => $v){ $cnt[$j]--; // echo $j.":".$cnt[$j]." "; if($sw[$i]){ $sw[$j] = !$sw[$j]; } if($cnt[$j] == 0){ $q->enqueue($j); } } // echo PHP_EOL; } //echo "------------".PHP_EOL; echo $ans; echo PHP_EOL; echo implode(PHP_EOL, $ans2);