City Signal Span
The municipal emergency office is designing a rapid broadcast plan for an upcoming drill. Every intersection is labeled with a number from 0 to n - 1, and the planners documented which intersections share a two-way road. When a transmitter activates at one intersection, the signal can travel through any connected road and continue hopping as long as new roads appear. Your goal is to reason about how far that announcement spreads when given a complete list of the available roads. Treat the map as dependable: each road can be traversed back and forth, and there are no hidden shortcuts or diagonal links beyond what the list describes.
Your task is to write a function that receives the total number of intersections n, a list of direct roads, and a starting intersection start. Each road is represented by two integers showing the intersections that share that road. Multiple roads between the same pair may appear, and the list order does not matter. The broadcast should be considered successful for every intersection that can be reached by following one road after another, regardless of the number of steps. Return the count of unique intersections that hear the message, including the starting point itself. If the map contains intersections that are isolated from the starting point, they do not contribute to the count.
Pay attention to special cases when building the result. An empty road list means the message never leaves the starting point. Repeated entries should not inflate the total because they describe the same connection. When the map reports several disconnected groups of intersections, the broadcast remains within the group that holds the starting point. The planners expect a precise integer answer, so make sure the function never rounds or formats the count. Focus on determining all unique intersections connected to start through the listed roads, then summarize that set by its size.
Example 1:
Input: n = 4, roads = [[0,1],[1,2],[2,3]], start = 0
Output: 4
Explanation: The signal travels along every road and covers all four intersections.
Example 2:
Input: n = 5, roads = [[0,1],[1,2],[3,4]], start = 1
Output: 3
Explanation: Intersections 0, 1, and 2 share a chain of roads, while 3 and 4 are separate.
Example 3:
Input: n = 6, roads = [[0,1],[1,2],[2,0],[3,4]], start = 5
Output: 1
Explanation: Intersection 5 is isolated, so only the starting point receives the broadcast.
Related Problems
No related problems found
Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
