<p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[i]</code> denotes the value of the <code>i<sup>th</sup></code> node. You are also given a 2D integer array <code>edges</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> denotes that there exists an <strong>undirected</strong> edge connecting nodes <code>a<sub>i</sub></code> and <code>b<sub>i</sub></code>.</p>
<p>A <strong>good path</strong> is a simple path that satisfies the following conditions:</p>
<ol>
<li>The starting node and the ending node have the <strong>same</strong> value.</li>
<li>All nodes between the starting node and the ending node have values <strong>less than or equal to</strong> the starting node (i.e. the starting node's value should be the maximum value along the path).</li>
</ol>
<p>Return <em>the number of distinct good paths</em>.</p>
<p>Note that a path and its reverse are counted as the <strong>same</strong> path. For example, <code>0 -> 1</code> is considered to be the same as <code>1 -> 0</code>. A single node is also considered as a valid path.</p>