Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2 C
Directed acyclic graph on vertices 0 to 5 with weighted edges (u→v (w)): 1→4 (7), 4→5 (5), 3→5 (9), 0→2 (2), 2→5 (8), 0→4 (3), 3→2 (3), 3→4 (1), 1→5 (4). What is the largest total weight of a directed path that starts at 0 and ends at 5?
- A. 12
- B. 2
- C. 18
- D. 10
Correct answer: D. 10
Relaxing in topological order with max instead of min gives 0 → 2 → 5 = 2 + 8 = 10. Letting the path start at 1 finds 1 → 4 → 5 = 12, 2 counts arcs instead of weight, and 18 adds the longest and shortest (0 → 4 → 5 = 8) routes.
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
- Directed acyclic graph on vertices 0 to 6 with weighted edges (u→v (w)): 1→6 (1), 2→4 (4), 2→3 (5), 2→6 (5), 3→4 (6), 4→6 (1), 1→2 (8)…
- Directed acyclic graph on vertices 0 to 7 with weighted edges (u→v (w)): 3→1 (6), 2→1 (9), 1→5 (9), 4→3 (8), 3→5 (3), 1→6 (5), 2→3 (7)…
- Directed acyclic graph on vertices 0 to 6 with weighted edges (u→v (w)): 3→2 (8), 2→6 (7), 4→6 (9), 0→2 (5), 4→2 (2), 5→1 (9), 3→5 (4)…
- Directed acyclic graph on vertices 0 to 7 with weighted edges (u→v (w)): 2→7 (1), 0→7 (4), 4→2 (4), 6→2 (9), 0→1 (9), 0→6 (1), 4→5 (6)…
- Directed graph on vertices 0 to 7 with non-negative weights (u→v (w)): 3→4 (3), 0→6 (18), 6→7 (2), 4→5 (3), 0→2 (15), 1→0 (15), 1→6 (17)…
- Directed graph on vertices 0 to 5 with non-negative weights (u→v (w)): 3→0 (19), 0→1 (3), 1→2 (2), 3→4 (1), 3→5 (8), 4→3 (8), 0→3 (14)…