You are given a bunch of sticks. For each stick, its two ends are labelled with two numbers (1~6, possibly same). You can connect two stick A and B, if and only if one of numbers of stick A is the same as one of the numbers of stick B. For example, a stick with [1,5] can be connected with a stick with [1,4] by connecting the two ends labelled as 1. In this case, these two sticks will become one with longer length, and its two ends now becomes [4,5]. Assume for each given stick, its length is 1. The question asks what is the longest stick one can get after performing connection.
Example 1:
Input: [1, 2], [1, 3], [1, 4]
Output: 2
Explanation: You can choose any two of the given sticks, then connect them by
the ends labelled with 1. But there is no way to connect all 3 sticksExample 2:
Input: [1, 6], [3, 4], [5, 6], [4, 1]
Output: 4
Explanation: You can connect all four sticks in the following way:
[3, 4] <-> [4, 1] <-> [1, 6] <-> [6, 5]