Company: Gameskraft_17_dec
Difficulty: medium
Count Tree Paths Problem Description You're given a tree describing dependencies between products, made up of treeNodes vertices. The connections are supplied through two arrays, treeFrom and treeTo , both of length treeNodes - 1 , where each index i connects treeFrom[i] to treeTo[i] . For this tree, count how many vertex triplets (i, j, k) satisfy both of the following: 0 ≤ i < j < k < treeNodes No single simple path passes through all three of i, j, and k. Because the count of such triplets can grow large, return it modulo (10 9 + 7). Notes A path here means a sequence of vertices where consecutive vertices are directly connected, reflecting a dependency link between products. A path visiting no vertex more than once is called a simple path. Example (from problem description) Given treeNodes = 5 , treeFrom = [1, 1, 0, 0] , treeTo = [0, 2, 3, 4] These vertex triplets have no simple path running through all three of them: (1, 3, 4) (2, 3, 4) 2 modulo (10 9 + 7) = 2, so retu