#abc254e. [abc254_e]Small d and k
[abc254_e]Small d and k
Problem Statement
We have a simple undirected graph with vertices and edges. The vertices are numbered . For each , the -th edge connects Vertex and Vertex . Additionally, the degree of each vertex is at most .
For each , answer the following query.
- Find the sum of indices of vertices whose distances from Vertex are at most .
Constraints
- $0 \\leq M \\leq \\min (\\frac{N(N-1)}{2},\\frac{3N}{2})$
- , if .
- The degree of each vertex in the graph is at most .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the answer to the -th query.
Sample Input 1
6 5
2 3
3 4
3 5
5 6
2 6
7
1 1
2 2
2 0
2 3
4 1
6 0
4 3
Sample Output 1
1
20
2
20
7
6
20
For the -st query, the only vertex whose distance from Vertex is at most is Vertex , so the answer is .
For the -nd query, the vertices whose distances from Vertex are at most are Vertex , , , , and , so the answer is their sum, .
The -rd and subsequent queries can be answered similarly.