Count Pythagorean Distance Triples in a Tree

Given an unweighted tree with N nodes and three fixed nodes x, y, and z, consider every node v in the tree.

Compute:

  • d(v, x)
  • d(v, y)
  • d(v, z)

Sort these three distances into no...

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Standard Input
Execution Result: