Data Structures & AlgorithmsHardCodeforces Div 2 D · 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. .... .... 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. 7
- B. 6
- C. 12
- D. 15
Correct answer: A. 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
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→E (6), S→A (2), S→C (2), S→T (6), E→T (2), D→A…
- A directed graph has the vertices D, E, H, I, K, N, O and the arcs N→E, N→D, K→N, K→O, E→O, I→N, I→E, H→K, O→N. How many strongly…
- A tree has the vertices A, C, M, R, V, Y, Z and the edges C–M, M–A, C–R, A–Y, A–V, R–Z. A set D dominates the tree if every vertex is in D…
- A directed graph with no directed cycles has arcs u→v (weight) : F→S (3), F→N (0), F→C (8), G→X (2), G→C (4), S→X (3), N→X (1), N→C (6)…
- A connected undirected graph has the vertices B, E, G, K, Q, R, S, V and the edges Q–K, K–B, K–G, K–S, G–V, G–R, G–E, S–E, R–E. Parallel…
- 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…