Data Structures & AlgorithmsHardGATE CS · ICPC regional
Grid with 4 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .G.G G... G... G... Each step, which is a move to an adjacent cell or waiting one unit in place, takes exactly 1 time unit. A gate may only be occupied at an even time (t = 0, 2, 4, …); normal cells can be occupied at any time. You start at the top-left cell at time 0. What is the earliest time you can stand on the bottom-right cell?
- A. 6
- B. 12
- C. 15
- D. 7
Correct answer: D. 7
BFS over (cell, time parity) states, with waiting allowed, gives 7: a gate can only be entered at an even time, so one wait is needed. Ignoring the gate rule gives the plain shortest path 6; waiting after every move gives 12, and 15 visits every cell.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- An undirected connected graph on 6 vertices has the edges (weights in brackets, all distinct): U–A (27), Y–M (6), I–Y (29), U–M (21), A–M…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {2, 5} and s ≤ the pile size. The player who…
- An undirected graph has the vertices B, O, P, Q, T, V, Z and the edges Q–Z, Q–V, Q–T, P–Z, P–B, P–T, Z–O, Z–V, O–B. What is the size of a…
- A tree on the vertices C, F, I, R, V, X has the arcs C→R, V→C, I→V, V→X, F→V (each undirected edge is directed as shown). You may reverse…
- A directed acyclic graph has the vertices A, E, F, H, N, Q, R and the edges Q→N, Q→H, A→N, A→F, N→R, N→F, H→R, H→A, H→E. A topological…
- A directed acyclic graph has the vertices K, L, P, U, W, X, Y and the directed edges Y→W, Y→K, K→L, K→X, P→K, U→X, W→X, W→P, U→P, U→K…