Tree: , , , . Target length: . Centroid is . Distances from : node is , node is , node is , node is , node is . Pairs with sum : node (distance ) with node (distance ). That is one path: .
Check child subtrees: subtree rooted at contains , subtree at contains . No pairs within a single subtree sum to . Recurse on components: each is small, no additional paths. Total: path of length .