#K63912. Sum of Adjacent Node Values
Sum of Adjacent Node Values
Sum of Adjacent Node Values
In this problem, you are given a graph with ( n ) nodes and ( m ) edges. Each node is assigned a unique integer value. Your task is to compute, for every node, the sum of the values of all the nodes directly connected to it by an edge.
The graph is undirected and contains no self-loops. If a node does not have any adjacent nodes, its sum is 0.
Formally, for every node ( i ), if ( A(i) ) denotes the set of nodes adjacent to ( i ), then you need to compute ( S(i) = \sum_{j \in A(i)} v_j ) where ( v_j ) is the value assigned to node ( j ).
inputFormat
Input is read from standard input (stdin).
The first line contains two integers ( n ) and ( m ) representing the number of nodes and edges, respectively.
The second line contains ( n ) space-separated integers representing the values of the nodes (indexed from 1 to ( n )).
The following ( m ) lines each contain two integers ( u ) and ( v ) which indicate that there is an undirected edge between node ( u ) and node ( v ).
outputFormat
Output the computed sums for each node in a single line, separated by spaces. The ( i^{th} ) number in the output should represent the sum of the values of all nodes that are directly connected to node ( i ) via an edge.## sample
5 4
1 3 2 4 5
1 2
1 3
2 4
3 5
5 5 6 3 2