Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2
Directed acyclic graph on vertices A, B, C, D, E, F, G (edges go from earlier to later letters) with weights A→B (3), A→D (4), A→E (4), A→F (4), B→C (3), B→E (2), C→D (3), C→F (3), C→G (2), D→G (4), E→F (1), E→G (3). Count the number of DIFFERENT paths from A to G whose total weight is the minimum possible.
- A. 3
- B. 5
- C. 2
- D. 9
Correct answer: C. 2
The shortest distance is 9 and 2 distinct paths achieve it, found by DP that adds counts only on ties. Counting all paths, or reporting the distance, answers a different question.
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
- Points A(1,7), B(2,4), C(4,9), D(8,8), E(2,7) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| + |y1−y2|…
- An undirected graph has the vertices G, Q, R, U, Y, Z and the edges Q–Z, Y–Q, G–Z, R–Z, G–R, Y–R. How many simple cycles does it contain…
- A directed acyclic graph has the vertices F, H, J, K, L, N, R and the arcs H→J, H→R, H→N, K→J, K→F, K→N, L→R, L→F, J→R, J→F, J→N, R→F. Two…
- A directed acyclic graph has the vertices B, H, K, O, W and the arcs K→B, K→W, K→O, B→H, B→O, W→O. Two players alternately move a single…
- 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…
- A connected undirected graph has the vertices E, F, J, K, L, W, Y, Z and the edges Y–E, Y–W, E–Z, E–L, E–W, E–J, Z–L, Z–F, W–K. Parallel…