🎁 Exclusive Offer! Join our
Telegram Channel
to get **special discounts** and updates! 🚀
Question 50 - 100% Working Solution | Buy Now
Description
11 Live
Houses in Hackerland
The city of Hackerland has many houses, each of which is connected via roads. There are house_nodes number of houses, numbered 0 to house_nodes - 1, where each pair of houses is connected and has a unique shortest path between them. Thus, the network of houses and roads forms an undirected tree structure comprising house_nodes nodes and (house_nodes - 1) edges. Each of the edges has a value denoted by val[i], which can either be 0 or 1.
To summarize, the overall tree is represented as follows:
house_nodes: the number of nodes
house_from, house_to: the arrays representing an undirected edge between house_from[i] and house_to[i] for 1 ≤ i ≤ house_nodes - 1.
val[]: the value of each edge in the tree, which can be either 0 or 1.
Problem Statement
Given the network of houses and roads, the task is to find the number of sequences of length k (h[1], h[2], ... h[k]) such that while visiting:
From house h[1] to h[2],
Then from h[2] to h[3],
And so on until reaching house h[k],
Using the unique shortest path between them, at least one edge with value '1' is visited.