Data Structures & AlgorithmsModerateCodeforces Div 2 D · ICPC regional
Each cell of a grid with 3 rows and 3 columns has an arrow: R = right, L = left, U = up, D = down. ULU LUR ULU From a cell you may move to any of its four side-adjacent cells. Moving in the direction of the cell's arrow costs 0; moving in any other direction costs 1. What is the minimum total cost from the top-left cell to the bottom-right cell?
- A. 8
- B. 3
- C. 4
- D. 5
Correct answer: C. 4
A 0-1 BFS (cost 0 along the arrow, 1 otherwise) gives 4. Ignoring the arrows and counting moves gives 4, and the number of cells whose arrow is not R or D gives 8.
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 A, D, E, J, L, Q, T, W, X and weighted edges (weights in brackets): L–T (2), T–D (6), D–W (9), T–Q (6), Q–J (7), L–X…
- Each cell of a grid with 3 rows and 4 columns has an arrow: R = right, L = left, U = up, D = down. DLUL RUUR DLRD From a cell you may move…
- A directed graph with no directed cycles has arcs u→v (weight) : A→U (8), Z→U (1), Z→I (1), E→U (-2), E→I (2), U→C (4), U→I (5), C→I (-2)…
- A connected undirected graph has the vertices F, G, O, P, R, U, Y and the edges P–O, P–G, P–F, O–U, O–R, R–G, R–Y, Y–F. How many bridges…
- On an 6×6 chessboard, rows and columns are numbered 0 to 5, and squares are written (row, column). A knight moves in the usual L-shape…
- Grid with 3 rows and 3 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: ... ..G GG. Each step, which is a move to…