Network connection timestamp
Your task
A social network has n people labeled 0..n-1, all initially strangers. You get logs where each log is [timestamp, a, b] meaning a and b became acquainted at that timestamp; acquaintance is mutual and transitive (friends of friends are connected). Return the earliest timestamp at which every person is connected to every other person (directly or transitively). If they never all become connected, return -1. With only one person (n = 1) there is no one to connect to, so return -1. Timestamps are non-negative integers and may be unsorted.
Examples
earliest_all_connected(n: int, logs: list[list[int]]) -> intExample 1
Input
earliest_all_connected(4, [[20, 0, 1], [5, 2, 3], [10, 1, 2], [30, 0, 3]])Output
20