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