Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B
Grid with 4 rows and 3 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .GG 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. 5
- B. 10
- C. 6
- D. 11
Correct answer: C. 6
BFS over (cell, time parity) states, with waiting allowed, gives 6: a gate can only be entered at an even time, so one wait is needed. Ignoring the gate rule gives the plain shortest path 5; waiting after every move gives 10, and 11 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
- A tree has vertices with values in brackets: P[-4], S[4], V[7], U[1], G[-4], D[1]. The edges are P–S, S–V, V–U, S–G, S–D. A path is any…
- A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…
- A grid has 3 rows and 4 columns with these values (top to bottom): 6389 5169 6136 A path moves between side-adjacent cells (up, down, left…
- A directed acyclic graph has the vertices F, H, M, P, U, W and the arcs H→M, H→W, U→F, F→M, F→P, F→W, M→P, M→W. Two players alternately…
- An undirected graph has the vertices A, D, U, W, Y and the edges U–Y, A–D, A–Y, D–Y, W–Y, U–D, A–W, A–U. How many simple cycles does it…
- Floyd–Warshall runs on vertices 1 to 5 with these arcs u→v (weight): 1→2 (6), 1→3 (5), 1→5 (6), 2→3 (5), 2→4 (11), 3→1 (11), 3→2 (3), 3→4…