Who Learns the Secret After Timed Meetings
A configuration flag starts with two owners. People meet at scheduled times; if either attendee already holds the flag at that moment, both leave holding it. Determine everyone who ends up holding it.
Problem
Given n people (0-indexed), an integer firstPerson, and a list meetings where meetings[i] = [x, y, time] means persons x and y meet at the given time, the secret is known by person 0 and firstPerson at time 0. If a person knows the secret at a meeting, the other person learns it (instantly, possibly propagating within the same time). Return all people who know the secret after all meetings.
Input
An integer n, an integer firstPerson, and a list meetings of [x, y, time].
Output
A list of all people who know the secret (any order).
Constraints
- 2 <= n <= 100000
- 1 <= meetings.length <= 100000
- Meetings may share timestamps; sharing within a timestamp can chain.
Examples
Example 1
Input
n = 6, firstPerson = 1, meetings = [[1,2,5],[2,3,8],[1,5,10]]
Output
[0,1,2,3,5]
1 tells 2 at t=5, 2 tells 3 at t=8, 1 tells 5 at t=10; 4 never learns.
Example 2
Input
n = 4, firstPerson = 3, meetings = [[0,2,1],[1,3,1],[2,1,2]]
Output
[0,1,2,3]
Chained sharing eventually reaches everyone.