Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B
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). Weights may be negative. What is the minimum total weight of a path from A to I that uses at most 2 arcs?
- A. 10
- B. 13
- C. 12
- D. 14
Correct answer: B. 13
Plain Bellman–Ford with k rounds (relaxing only through paths of length at most 2) gives 13. Ignoring the limit gives 10, and only paths of exactly 2 arcs give 13.
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 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…
- A grid has 6 rows and 5 columns (top to bottom; '.' open, '#' blocked): ...#. .#..# ..... ##.#. ..... ..... You may only move right or…
- An undirected connected graph on 5 vertices has the edges (weights in brackets, all distinct): V–H (5), V–D (15), V–X (10), X–D (26), V–Z…
- Each cell of a grid with 5 rows and 3 columns has an arrow: R = right, L = left, U = up, D = down. ULR UUD ULL LUL UDU From a cell you may…