You are given an n-ary tree representing a network of transformers. Each node in the tree is a transformer with a specific integer voltage value.
The entire network is considered stable if and only if every transformer in the network adheres to a strict stability rule. The rule is as follows:
For any given transformer (node), the average voltage of all its descendants must be strictly less than the voltage of the transformer itself.
Your task is to determine if the given transformer network is stable.
Input Format:
The first line of input contains an integer 'N', the number of transformers (nodes).
The second line contains 'N' space-separated integers, where the i-th integer is the voltage of node i.
The third line contains 'N' space-separated integers, representing a parent array. The i-th integer is the parent of node i. The root node has a parent of -1.
Output Format:
Print the string STABLE if every node in the tree satisfies the stability rule.
Otherwise, print the string UNSTABLE.
Note:
A node's descendants are all the nodes in its subtree, excluding the node itself.
A leaf node has no descendants. The sum and count of its descendants are both 0. A leaf node is always considered stable by definition.
The problem uses 0-based indexing for nodes.