Data Structures & AlgorithmsHardCodeforces Div2 C · ICPC regional
A tree has these parent→child edges: 14→88, 60→62, 14→4, 4→60, 35→32, 62→35, 35→3, 60→49, 32→9, 4→20, 3→39. 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 5?
- A. 58
- B. 18
- C. 11
- D. 9
Correct answer: D. 9
Count each unordered pair once: enumerate the pairs and tally their distances, then read off distance 5. Counting ordered pairs, or the cumulative count up to 5, 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: 77→82, 6→30, 6→28, 22→77, 82→6, 21→73, 6→44, 21→22, 28→48, 73→89, 82→93. The distance between two…
- A tree has these parent→child edges: 34→99, 85→14, 36→70, 14→34, 99→36, 76→62, 62→78, 62→92, 85→76, 76→73, 70→37, 92→84. The distance…
- A tree has these parent→child edges: 45→55, 55→70, 48→90, 70→12, 48→20, 90→26, 15→33, 20→45, 90→15, 26→97, 90→84, 90→87. The distance…
- A tree has these parent→child edges: 11→14, 35→84, 26→96, 11→19, 50→26, 84→79, 81→16, 33→10, 35→44, 50→81, 84→33, 50→35, 33→67, 35→11. The…
- 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…
- 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…