Data Structures & AlgorithmsHardGATE CS · ICPC regional
Directed acyclic graph on vertices A, B, C, D, E, F, G (every edge goes from a smaller to a larger letter) with weighted edges A→E (8), A→F (1), A→G (7), B→C (2), B→D (5), C→D (6), D→G (7), E→G (2), F→G (8). What is the largest total weight of any directed path (one or more edges) in this graph?
- A. 15
- B. 46
- C. 8
- D. 3
Correct answer: A. 15
A DP over vertices in topological order gives a heaviest path of weight 15. Counting the edges of that path, or summing every weight, gives other numbers.
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
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…
- Directed weighted graph on vertices A, B, C, D, E with edges listed in this exact order: C→A (3); E→C (7); B→C (-2); B→D (6); A→B (5); C→E…
- Undirected graph on vertices A, B, C, D, E, F, G with edges A–D (1), A–E (1), A–G (1), B–C (1), B–F (1), B–G (1), D–F (1), D–G (1), E–G…
- Array A = [9, 1, 6, 12, 6, 8]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in the…
- Rooted tree with root 0 and vertices 0 to 7; the edges are 0–1, 1–2, 1–3, 1–4, 3–5, 2–6, 4–7 (parent–child). Every edge has length 1. What…
- Undirected weighted graph on vertices A, B, C, D, E; its edges, in this listed order, are: D–E (3), C–E (3), A–C (2), B–C (1), A–E (8)…