SP4882 DAGCNT2 - Counting in a DAG
Description
You are given a weighted DAG. For each vertex, calculate the sum of the weights of the vertices within its reach (including itself).
Input Format
The first line contains an integer T, denoting the number of test cases.
For each test case, the first line contains two positive integers n and m, denoting the number of vertices and the number of edges in the DAG.
The second line contains n positive integers w $ _{1} $ ..w $ _{n} $ , denoting the weights of vertices.
The next m lines contain two positive integers u,v, denoting an edge from u to v.
Output Format
For each test case, print a line consisting of n numbers, denoting the sum for each vertex.