Data Structures & AlgorithmsVery hardCodeforces Div2 C · ICPC regional
A tree has these parent→child edges: 66→83, 25→54, 66→58, 25→74, 63→51, 63→25, 54→12, 51→39, 12→34, 14→66, 83→63. The distance between two nodes is the number of edges on the path between them. How many unordered pairs of distinct nodes are at distance exactly 2?
- A. 13
- B. 24
- C. 26
- D. 11
Correct answer: A. 13
Count each unordered pair once: enumerate the pairs and tally their distances, then read off distance 2. Counting ordered pairs, or the cumulative count up to 2, doubles or inflates the answer.
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
- A tree has these parent→child edges: 81→82, 3→69, 3→57, 57→74, 86→4, 68→86, 4→38, 57→83, 3→81, 81→55, 82→68, 4→97. The distance between…
- A tree has these parent→child edges: 84→65, 30→38, 12→63, 61→10, 10→82, 84→12, 63→95, 61→30, 19→61, 92→26, 92→19, 84→92. The distance…
- A tree has these parent→child edges: 10→77, 73→37, 10→96, 88→54, 35→10, 77→11, 35→34, 10→73, 82→99, 88→82, 73→23, 96→88. The distance…
- A binary search tree has 5 distinct keys and preorder traversal 34 18 6 29 57. How many of the 5! orders in which these keys can be…
- A binary search tree has 5 distinct keys and preorder traversal 37 5 33 53 39. How many of the 5! orders in which these keys can be…
- A binary search tree has 4 distinct keys and preorder traversal 19 26 58 50. How many of the 4! orders in which these keys can be…