First Timestamp When All People Are Connected. People are labeled0 through n-1. A log [timestamp,x,y] adds a symmetric friendship between x and y, which persists.
### Problem
People are labeled 0 through n-1. A log `[timestamp,x,y]` adds a symmetric friendship between x and y, which persists. Acquaintance includes friendship chains. Return the earliest logged timestamp when every person is connected to every other, or -1 if this never happens.
```cpp
class Solution {
public:
int earliestAcq(vector<vector<int>>& logs, int n);
};
```
### Examples
**Example 1:**
```text
Input: logs = [[8,0,1],[3,1,2]], n = 3
Output: 8
Explanation: At3 only1 and2 are connected; the event at8 connects person0.
```
**Example 2:**
```text
Input: logs = [[1,0,1],[2,2,3]], n = 4
Output: -1
Explanation: The two pairs remain in separate components.
```
### Constraints
- `2 <= n <= 100`; the log list has 1 to 10000 entries.
- Every log contains exactly three integers.
- Timestamps lie in `[0,1000000000]` and are all distinct.
- Each endpoint lies in `[0,n-1]`, with distinct endpoints in a log.
- Each endpoint pair occurs at most once.
### Contract considerations
Timestamps are numeric event labels, not a required calendar format.
```hint Read the boundary condition
Could a later-listed log have an earlier timestamp, and how does that affect the meaning of the requested earliest time?
```
### Boundary reminders
Timestamps are numeric event labels, not a required calendar format.
Overview: First Timestamp When All People Are Connected. People are labeled0 through n-1. A log [timestamp,x,y] adds a symmetric friendship between x and y, which persists.
People are labeled 0 through n-1. A log [timestamp,x,y] adds a symmetric friendship between x and y, which persists. Acquaintance includes friendship chains. Return the earliest logged timestamp when every person is connected to every other, or -1 if this never happens.
class Solution {
public:
int earliestAcq(vector<vector<int>>& logs, int n);
};
Examples
Example 1:
Input: logs = [[8,0,1],[3,1,2]], n = 3
Output: 8
Explanation: At3 only1 and2 are connected; the event at8 connects person0.
Example 2:
Input: logs = [[1,0,1],[2,2,3]], n = 4
Output: -1
Explanation: The two pairs remain in separate components.
Constraints
2 <= n <= 100
; the log list has 1 to 10000 entries.
Every log contains exactly three integers.
Timestamps lie in
[0,1000000000]
and are all distinct.
Each endpoint lies in
[0,n-1]
, with distinct endpoints in a log.
Each endpoint pair occurs at most once.
Contract considerations
Timestamps are numeric event labels, not a required calendar format.
Boundary reminders
Timestamps are numeric event labels, not a required calendar format.