Dsa
Graphs Dfs
Easy
The Ghostly Galleries
An old museum has N galleries (labeled 0 to N-1) connected by M one-way corridors. A tour starts at gallery 0. Some galleries might be impossible to reach because of renovations. Your task is to identify all 'Ghost Galleries'—those that cannot be reached starting from gallery 0.
Input: The first line contains N and M. The next M lines each contain two integers u and v, representing a one-way corridor from gallery u to gallery v.
Output: A space-separated list of the Ghost Gallery IDs in ascending order. If all galleries are reachable, print 'NONE'.
Example:
Input:
5 4
0 1
1 2
0 3
3 1
Output:
4
Key concepts
graphs_dfsreachability
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