Data Structures & AlgorithmsHardCodeforces Div 2 · 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→B (4), A→D (4), B→C (7), B→E (3), B→G (2), D→F (7), D→G (6), E→G (1). What is the largest total weight of any directed path (one or more edges) in this graph?
- A. 11
- B. 2
- C. 7
- D. 34
Correct answer: A. 11
A DP over vertices in topological order gives a heaviest path of weight 11. 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
- Points A(8,5), B(3,9), C(3,5), D(2,7), E(3,2) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| + |y1−y2|…
- Directed weighted graph on vertices A, B, C, D, E with edges D→C (0); B→D (2); A→D (-1); E→A (-1); B→C (0); B→A (-2); C→E (4); D→E (-1)…
- Array A = [7, 4, 7, 14, 7, 6, 2]. 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 9; the edges are 0–1, 1–2, 1–3, 2–4, 2–5, 4–6, 5–7, 7–8, 0–9 (parent–child). Every edge has…
- Points A(4,4), B(3,6), C(2,6), D(2,3), E(3,5), F(8,4) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| +…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–C (1), B–D (1), B–G (1), C–D (1), C–E (1), D–E (1), E–F (1), E–G (1)…