Problem 2867 · Hard

Count Valid Paths in a Tree

Walk outward from every node while counting primes on the path; a pair counts when exactly one node on it is prime.

Open the interactive visualisation