Modeling the transit graph: bus routes are nodes, not bus stops. Boarding a bus gives free access to all its stops. Precompute a stop-to-routes index and mark entire bus lines visited to prevent $O(S^2)$ clique explosion.
"Modeling stops as nodes causes dense clique graphs: a single bus with 500 stops has $(500 \times 499)/2 \approx 1.2 \times 10^5$ edges. Modeling the bus route itself as a node keeps the graph small ($N \le 500$)."
"We build a Map<Integer, List<Integer>> stopToRoutes mapping each bus stop to all bus lines serving it in $O(\sum |routes[i]|)$."
"The BFS queue holds bus routes and step distance. Once route $r$ is boarded, mark visitedRoutes[r] = true so we never board it again."
"Every bus route and stop is inspected at most once. Time is $O(\sum |routes[i]|)$ and space is $O(\sum |routes[i]|)$."