Thanksgiving Sale: Use Coupon Code THANKS25 to Get Extra 25% Off.
valuesToNodes to map each value to the list of nodes with that value, sorted by keys.find and union_set methods.goodPaths to count the number of good paths.valuesToNodes in ascending order.
group to count the number of nodes in each component.size * (size + 1) / 2 and add it to goodPaths.goodPaths.