Computer Science, asked by sonu0510pa0bla, 6 months ago

Problem Description
You are given a rooted tree containing N vertices numbered from 1 to N and rooted at vertex numbered 1.
Let's call vertex x a 1-ancestor of vertex y, if x is the parent of vertex y.
Let'c call vertex x a p-ancestor of vertex y, if vertex y has a 1-ancestor, and x is a (p-1)-ancestor of b's 1-ancestor.
You can color each vertex in any of the two possible colours {red, green).
You need to find the total number of different ways to completely color the tree such that in each possible coloring every vertex has a different color assigned then its p-th ancestor.
Return the total number of ways modulo 10° + 7.
NOTE:
.
In the given tree the hierarchy starts from vertex numbered 1.
Two ways are consider different if there exist atleast one vertex that is colored with different colors.​

Answers

Answered by Gauravs41
3

Answer:

Follow the code given in Image, I will upload full explanation soon. If you need solution urgently please do comment. Thank you.

Explanation:

Attachments:
Similar questions