n people numbered from 0 to n - 1. Everyone has a different amount of money, but the exact sums are unknown: there is only a list of comparisons richer, where the pair [a, b] means that a is richer than b. The comparisons are consistent.
Also, volume[i] is how loud person i speaks; all volumes are distinct.
For each person x, look at everyone who is *certainly* at least as rich: x themselves and everyone richer than x through a chain of comparisons. Among them, find the quietest one, the one with the smallest volume.
Return an array answer of length n where answer[x] is that person's number.richer=[[2, 0], [1, 2], [3, 1]], volume=[1, 2, 3, 0] → [3, 3, 3, 3]
Person 3 is richer than 1, 1 than 2, and 2 than 0, so person 3 is surely at least as rich as each of them. With volume 0 this person is the quietest, so 3 is everyone's answer.
richer=[[0, 1], [0, 2]], volume=[2, 0, 1] → [0, 1, 2]
Nobody is known to be richer than person 0, so 0 is their own answer. For 1 the candidates are 0 and 1, and 1 is quieter. For 2 the candidates are 0 and 2, and 2 is quieter.
richer=[], volume=[1, 0] → [0, 1]
With no comparisons, everyone is their own answer.
n = len(volume) ≤ 10⁴volume[i] ≤ 10⁴, all values are distinctlen(richer) ≤ n · (n − 1) / 2richer[i] = [a, b], 0 ≤ a, b < n, a ≠ bricher are distinct, and the comparisons form no cyclericher=[[2, 0], [1, 2], [3, 1]], volume=[1, 2, 3, 0]
[3, 3, 3, 3]
Run checks the first 3 tests in your browser. Submit checks all 95 tests on the server, hidden ones included.