You are given n entities labeled 0 to n - 1 and a list of connection logs logs. Each log is [timestamp, x, y] and means x and y became directly connected at timestamp. The logs are not necessarily in time order.
Connectivity is transitive: if a is connected to b and b is connected to c, then a is connected to c.
Return the earliest timestamp at which every entity is connected to every other, directly or transitively. If that never happens, return -1.
Input: n = 4, logs = [[20,0,1],[50,2,3],[30,1,2],[70,0,3],[60,1,3]]
Output: 50
In time order: at 20 entities 0 and 1 join, at 30 entity 2 joins them, and at 50 entity 3 joins too, so all four are connected. Reading the logs in the given order would wrongly stop at 30.
Input: n = 4, logs = [[3,0,1],[7,1,2],[9,0,2]]
Output: -1
Entity 3 never appears in any log, so it is never connected to the others.
Input: n = 2, logs = [[0,1,0]]
Output: 0
The only two entities connect at timestamp 0.
2 <= n <= 1001 <= logs.length <= 10^4logs[i].length == 30 <= logs[i][0] <= 10^90 <= logs[i][1], logs[i][2] <= n - 1logs[i][1] != logs[i][2]