There exists an undirected and unrooted tree with n nodes indexed from 0
to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.
Each node has an associated price. You are given an integer array price, where price[i] is the price of the ith node.
The price sum of a given path is the sum of the prices of all nodes lying on that path.
Additionally, you are given a 2D integer array trips, where trips[i] = [starti, endi] indicates that you start the ith trip from the node starti
and travel to the node endi by any path you like.
Before performing your first trip, you can choose some non-adjacent nodes and halve the prices.
Return the minimum total price sum to perform all the given trips.

Input: n =4, edges =[[0,1],[1,2],[1,3]], price =[2,2,10,6], trips =[[0,3],[2,1],[2,3]]Output: 23Explanation: The diagram above denotes the tree after rooting it at node 2. The first part shows the initial tree and the second part shows the tree after choosing nodes 0,2, and 3, and making their price half.For the 1st trip, we choose path [0,1,3]. The price sum of that path is1+2+3=6.For the 2nd trip, we choose path [2,1]. The price sum of that path is2+5=7.For the 3rd trip, we choose path [2,1,3]. The price sum of that path is5+2+3=10.The total price sum of all trips is6+7+10=23.It can be proven, that 23is the minimum answer that we can achieve.

Input: n =2, edges =[[0,1]], price =[2,2], trips =[[0,0]]Output: 1Explanation: The diagram above denotes the tree after rooting it at node 0. The first part shows the initial tree and the second part shows the tree after choosing node 0, and making its price half.For the 1st trip, we choose path [0]. The price sum of that path is1.The total price sum of all trips is1. It can be proven, that 1is the minimum answer that we can achieve.
Each trip increases the usage count of nodes along its path. To minimize the total price, we can halve the price of some nodes (but not adjacent ones). This is a classic tree DP problem: for each node, decide whether to halve its price or not, ensuring no two adjacent nodes are halved.
defminimize_total_price(n: int, edges: list[list[int]], price: list[int], trips: list[list[int]]) -> int:
from collections import defaultdict
g = defaultdict(list)
for a, b in edges:
g[a].append(b)
g[b].append(a)
cnt = [0] * n
defdfs(u: int, v: int, p: int) -> bool:
if u == v:
cnt[u] +=1returnTruefor x in g[u]:
if x != p and dfs(x, v, u):
cnt[u] +=1returnTruereturnFalsefor s, e in trips:
dfs(s, e, -1)
defdp(u: int, p: int) -> tuple[int, int]:
half = cnt[u] * price[u] //2 full = cnt[u] * price[u]
for x in g[u]:
if x != p:
h, f = dp(x, u)
half += f
full += min(h, f)
return half, full
h, f = dp(0, -1)
return min(h, f)