Double-Degree Array solved by 1951

Feb. 21, 2014, 4:22 p.m. by Rosalind Team

Topics: Graphs

Problem

Figure 1. The graph from the dataset

Source: Algorithms by Dasgupta, Papadimitriou, Vazirani. McGraw-Hill. 2006.

Given: A simple graph with $n \le 10^3$ vertices in the edge list format.

Return: An array $D[1..n]$ where $D[i]$ is the sum of the degrees of $i$'s neighbors.

See Figure 1 for visual example from the sample dataset.

Sample Dataset

5 4
1 2
2 3
4 3
2 4

Sample Output

3 5 5 5 0

Adjacency list data structure

An adjacency list data structure may come in useful.

Please login to solve this problem.