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 .GGG GG.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. 7
- C. 12
- D. 15
Correct answer: B. 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 connected undirected graph has the vertices A, B, E, J, M and weighted edges (weights in brackets): M–E (8), A–E (17), M–B (10), A–B…
- An undirected graph has the vertices B, D, O, Q, T, X and the edges D–Q, X–D, B–D, X–Q, O–D, X–T, B–Q, D–T, X–O. What is the minimum…
- A directed acyclic graph has the vertices A, E, F, J, L, N and the arcs F→N, F→E, F→J, F→A, L→E, N→E, E→A, J→A. Two players alternately…
- A bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, Q4, Q5, with edges P1–Q1, P4–Q1, P1–Q2, P1–Q5, P4–Q5, P2–Q5…
- A tree has vertices with weights in brackets: Y[6], L[12], B[1], X[10], W[6], I[3], N[4], V[14], J[7]. The edges are Y–L, Y–B, L–X, L–W…
- A directed graph has the vertices D, F, M, O, S and the arcs M→D, M→O, D→O, D→F, O→S, F→O, S→M. Count the directed Hamiltonian paths…