Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You are given a tree rooted at node 1 with N nodes. Each node i has a value C [ i - 1 ] .
You are given a tree rooted at node with N nodes. Each node i has a value Ci
You need to choose a subset of nodes that satisfies the following conditions:
For any two nodes u v of the chosen subset, if node w is a common ancestor for u and v then distuw distvw
For any two nodes u v of the chosen subset where disturoot distvroot then parentv u
The value of the subset is the sum of the values of the chosen nodes.
Find the maximum possible value of a chosen subset. Since the answer may be large return it modulo
Python code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started