#P11378. Igniting the Tree
Igniting the Tree
Igniting the Tree
A tree with \(n\) nodes is given, where each node \(i\) has an associated weight \(a_i\). You may choose an initial node to ignite. A burning node will ignite each of its adjacent nodes if and only if that neighboring node's weight is < the burning node's weight. The fire then spreads from all newly ignited nodes in the same fashion until no further nodes can be ignited.
Your task is to determine the maximum number of nodes that can be burned by choosing the optimal initial ignition node.
Formal Description:
Given a tree with \(n\) nodes and weights \(a_1, a_2, \dots, a_n\), when a node with weight \(a_u\) is burning, it may ignite an adjacent node \(v\) if \(a_v < a_u\). Once a node is ignited, it remains burning permanently and can in turn ignite its eligible neighbors. Compute the maximum number of nodes that can be burned by optimally choosing the initial node.
inputFormat
The input consists of multiple lines:
- The first line contains an integer (n) ((1 \leq n \leq 10^5)), representing the number of nodes in the tree.
- The second line contains (n) integers (a_1, a_2, \dots, a_n), where (a_i) is the weight of the (i)-th node.
- Each of the following (n - 1) lines contains two integers (u) and (v) ((1 \le u, v \le n)), denoting an edge between node (u) and node (v).
outputFormat
Output a single integer representing the maximum number of nodes that can be burned by an optimal choice of the initial ignition node.
sample
3
3 2 1
1 2
2 3
3