Question bank › Graphs Bfs
Dsa Graphs Bfs Easy

Urban Paths

In an urban area, intersections and streets create a graph-like structure. Each intersection is a node and each street is an edge between nodes. Given the number of intersections and a list of streets connecting them, you need to determine the number of distinct intersections that can be visited from a given starting intersection using only one direct path to each other intersection. Input format: - The first line contains two integers n (1 <= n <= 500) and m (0 <= m <= 2000), where n is the number of intersections and m is the number of streets. - The next m lines each contain two integers a and b (1 <= a, b <= n), indicating a direct street between intersection a and b. - The last line contains a single integer s (1 <= s <= n), which is the starting intersection. Output format: - Output a single integer, the number of distinct intersections reachable from s. Example: Input: 4 3 1 2 2 3 1 3 1 Output: 3

Key concepts

graphsbfsurban_planning

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.