#C5257. Graph Edge Distance Calculation
Graph Edge Distance Calculation
Graph Edge Distance Calculation
You are given a graph with n nodes and m edges. Each node has an associated weight given in an array. The weight of an edge connecting nodes u and v is defined as the sum of the weights of these two nodes, i.e., in LaTeX format: \(w(u,v)=w(u)+w(v)\). Your task is to compute the distance for each edge in the order they are provided.
Input Format: 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 weights of the nodes. Each of the next m lines contains two integers u and v, representing an edge between nodes u and v. All node indices are 1-indexed.
Output Format: Output m integers separated by a space, where each integer is the weight of the corresponding edge computed as mentioned above.
inputFormat
The input is read from standard input (stdin) in the following format:
- The first line contains two integers n m.
- The second line contains n space-separated integers representing the weights of the nodes.
- The next m lines each contain two integers, u and v, denoting an edge between nodes.
outputFormat
The output is written to standard output (stdout) as a single line containing m space-separated integers. Each integer represents the sum of the weights of the two nodes connected by the corresponding edge.
## sample4 3
3 2 1 4
1 2
1 3
3 4
5 4 5