#abc254e. E - Small d and k
E - Small d and k
Score : points
问题描述
我们有一个简单的无向图,包含 个顶点和 条边。顶点编号为 。对于每条边 ,第 条边连接顶点 和顶点 。另外,每个顶点的度数最多为 。
对于每个查询索引 ,回答以下问题:
- 找出距离顶点 距离不大于 的所有顶点的索引之和。
以上为通义千问 qwen-max 翻译,仅供参考。
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
- , 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.
update @ 2024/3/10 10:49:52