atcoder#ABC254E. [ABC254E] Small d and k
[ABC254E] Small d and k
Score : points
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 3.
For each , answer the following query.
- Find the sum of indices of vertices whose distances from Vertex are at most .
Constraints
- , 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.
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
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.