
You are given an array pairs , where pairs[i] = [x _i , y _i ] , and:
There are no duplicates.
x _i < y _i
Let ways be the number of rooted trees that satisfy the following conditions:
The tree consists of nodes whose values appeared in pairs .
A pair [x _i , y _i ] exists in pairs if and only if x _i is an ancestor of y _i or y _i is an ancestor of x _i .
Note: the tree does not have to be a binary tree.
Two ways are considered to be different if there is at least one node that has different parents in both ways.
Return:
0 if ways == 0
1 if ways == 1
2 if ways > 1
A rooted tree is a tree that has a single root node, and all edges are oriented to be outgoing from the root.
An ancestor of a node is any node on the path from the root to that node (excluding the node itself). The root has no ancestors.
1 <= pairs.length <= 10 ^51 <= x _i < y _i <= 500The elements in pairs are unique.