<p>Let <code>ways</code> be the number of rooted trees that satisfy the following conditions:</p>
<ul>
<li>The tree consists of nodes whose values appeared in <code>pairs</code>.</li>
<li>A pair <code>[x<sub>i</sub>, y<sub>i</sub>]</code> exists in <code>pairs</code><strong>if and only if</strong><code>x<sub>i</sub></code> is an ancestor of <code>y<sub>i</sub></code> or <code>y<sub>i</sub></code> is an ancestor of <code>x<sub>i</sub></code>.</li>
<li><strong>Note:</strong> the tree does not have to be a binary tree.</li>
</ul>
<p>Two ways are considered to be different if there is at least one node that has different parents in both ways.</p>
<p>Return:</p>
<ul>
<li><code>0</code> if <code>ways == 0</code></li>
<li><code>1</code> if <code>ways == 1</code></li>
<li><code>2</code> if <code>ways > 1</code></li>
</ul>
<p>A <strong>rooted tree</strong> is a tree that has a single root node, and all edges are oriented to be outgoing from the root.</p>
<p>An <strong>ancestor</strong> of a node is any node on the path from the root to that node (excluding the node itself). The root has no ancestors.</p>