There are n people labeled 0 through n - 1. At time 0, person 0 shares a secret with firstPerson. Each entry [a, b, time] in meetings means people a and b meet at that time.
Whenever either participant knows the secret, they share it with the other. Sharing is instantaneous: someone can learn the secret in one meeting and pass it on in another meeting at the same time. People can attend multiple simultaneous meetings.
Return all people who know the secret after every meeting. You may return the people in any order, with each person listed once.
Example 1:
Input: n = 5
meetings = [[3,4,4],[2,3,4],[1,2,4]]
firstPerson = 1
Output: [0,1,2,3,4]Explanation: People 0 and 1 know the secret at time 0. At time 4, it passes from 1 to 2 to 3 to 4, all instantaneously. The order in which these simultaneous meetings are listed does not matter, so everyone learns the secret.
Example 2:
Input: n = 5
meetings = [[2,3,1],[1,2,2]]
firstPerson = 1
Output: [0,1,2]Explanation: At time 1, neither person 2 nor person 3 knows the secret. Person 2 learns it from person 1 at time 2, but the earlier meeting cannot share it retroactively. Only people 0, 1, and 2 know it.
Example 3:
Input: n = 4
meetings = [[2,3,1],[1,2,2],[2,3,3]]
firstPerson = 1
Output: [0,1,2,3]Explanation: The meeting at time 1 shares nothing. Person 2 learns the secret at time 2 and then shares it with person 3 in their new meeting at time 3. All four people eventually know the secret.
Constraints:
2 <= n <= 1000001 <= meetings.length <= 100000- Each meeting is
[a, b, time], with distinct people between0andn - 1. 1 <= time <= 1000001 <= firstPerson < n- People may attend multiple meetings at the same time.