1101. The Earliest Moment When Everyone Become Friends
1101. The Earliest Moment When Everyone Become Friends
Description
There are n people in a social group labeled from 0 to n - 1. You are given an array logs where logs[i] = [timestampi, xi, yi] indicates that xi and yi will be friends at the time timestampi.
Friendship is symmetric . That means if a is friends with b, then b is friends with a. Also, person a is acquainted with a person b if a is friends with b, or a is a friend of someone acquainted with b.
Return the earliest time for which every person became acquainted with every other person. If there is no such earliest time, return -1.
Example 1:
1 | Input: logs = [[20190101,0,1],[20190104,3,4],[20190107,2,3],[20190211,1,5],[20190224,2,4],[20190301,0,3],[20190312,1,2],[20190322,4,5]], n = 6 |
Example 2:
1 | Input: logs = [[0,2,0],[1,0,1],[3,0,3],[4,1,2],[7,3,1]], n = 4 |
Constraints:
2 <= n <= 1001 <= logs.length <= 10^4logs[i].length == 30 <= timestampi <= 10^90 <= xi, yi <= n - 1xi != yi- All the values
timestampiare unique . - All the pairs
(xi, yi)occur at most one time in the input.
Hints/Notes
- 2025/04/28 Q2
- union finid
- Leetcode solution
Solution
Language: C++
1 | class Solution { |