Hot Path Through Microservices
Your platform runs n microservices, numbered 1 to n. Cold-starting service i costs c_i
milliseconds of CPU: the first time a request reaches the service, the container has to warm up its
caches. After that, any further calls the same request makes into that service are free.
The tracing system has recorded m call edges. An edge u v means service u may call service v
while handling a request. The call graph is directed and may contain cycles (services call each other
back, retries loop, and so on), self-loops and repeated edges.
A request enters at some service and then follows call edges one after another, as long as it likes.
It may revisit services and edges any number of times, and it may stop anywhere, including at the
entry service. Its cold-start cost is the sum of c_i over all distinct services it reached,
the entry service included.
For capacity planning you need the worst case: for every possible entry service s, find the
largest cold-start cost a single request entering at s can incur.
Input
The first line contains two integers n and m (1 ≤ n ≤ 2·10^5, 0 ≤ m ≤ 2·10^5).
The second line contains n integers c_1, c_2, ..., c_n (0 ≤ c_i ≤ 10^9).
Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n): service u may call
service v. Self-loops (u = v) and repeated edges are allowed.
Output
Print n integers separated by spaces on one line: the s-th of them is the largest cold-start cost
of a request entering at service s.
Notes
In the first example, services 1, 2 and 3 call each other in a loop, and from that loop a request can
go either to service 4 (and on to 5) or to service 6. A request entering at 1 can tour the
whole loop for 1 + 2 + 3 = 6, then go to 4 and 5 for 4 + 5 more, total 15. It cannot also
reach 6 on the same request, because nothing leads back from 4 or 5. Going to 6
instead would give only 6 + 7 = 13.
In the second example there are no edges, so every request only reaches its entry service.
A single request is a single chain of calls: it cannot fan out into several branches at once. The answers can exceed 2^31.