Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Directed acyclic graph on vertices A, B, C, D, E, F (every edge goes from a smaller to a larger letter) with weighted edges A→D (9), A→E (5), B→C (1), B→D (3), B→E (8), B→F (6), C→D (9), D→E (3), E→F (2). What is the largest total weight of any directed path (one or more edges) in this graph?
- A. 46
- B. 4
- C. 15
- D. 9
Correct answer: C. 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
- Points A(3,7), B(3,5), C(9,0), D(8,2), E(5,4), F(5,6) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| +…
- A trie keeps a counter at each node, and every word of the list W = ['b', 'abb', 'cbb', 'abc', 'ca', 'ca', 'aacc', 'b'] is inserted once…
- Directed acyclic graph on vertices A, B, C, D, E, F (every edge goes from a smaller to a larger letter) with weighted edges A→D (7), A→E…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (1), A–C (3), A–E (1), B–C (2), B–D (3), C–E (3), D–E (3). An edge is…
- A binary trie of 6-bit numbers stores the set S = [35, 33, 47, 2, 38, 26, 51]. For the query x = 20, what is the maximum value of x XOR s…
- Weighted tree on vertices 0 to 5 with edges 0–1 (4), 0–2 (9), 0–3 (9), 2–4 (6), 0–5 (4). What is the largest possible sum of edge weights…