Earliest Unified Service Cluster

A distributed platform plans to deploy n independent service clusters, labeled 0 through n - 1. Each cluster starts fully isolated. Platform operators add bidirectional high-speed links between clusters over time. Every link is an entry [timestamp, clusterA, clusterB], meaning that at exactly timestamp, a direct link is opened between cluster clusterA and cluster clusterB. As soon as two clusters are linked, their two connected service meshes merge into one, and that connectivity is transitive: if cluster A is mesh-connected to B, and B is mesh-connected to C, then A, B, and C all belong to the same mesh.

Implement solve(n, logs) which returns the earliest timestamp at which all n clusters belong to a single connected service mesh. If the listed links never fully connect every cluster, return -1. A single cluster is trivially already a complete mesh, so when n === 1, the answer is 0.

Links may be recorded out of order, and a link between two clusters already in the same mesh has no effect. Each cluster only links to others within 0 to n - 1.

Examples
Input: [4,[[3,0,1],[5,0,2],[8,2,3]]]
Output: 8
Hints

Earliest Unified Service Cluster

A distributed platform plans to deploy `n` independent service clusters, labeled `0` through `n - 1`. Each cluster starts fully isolated. Platform operators add bidirectional high-speed links between clusters over time. Every link is an entry `[timestamp, clusterA, clusterB]`, meaning that at exactly `timestamp`, a direct link is opened between cluster `clusterA` and cluster `clusterB`. As soon as two clusters are linked, their two connected service meshes merge into one, and that connectivity is transitive: if cluster `A` is mesh-connected to `B`, and `B` is mesh-connected to `C`, then `A`, `B`, and `C` all belong to the same mesh.