#P12499. 「DLESS-1」Life Lies in Movement
「DLESS-1」Life Lies in Movement
Description
The town can be modeled as an undirected tree with nodes and edges. Each edge has a positive integer weight, and there is a household at each node. Let denote the sum of edge weights along the unique simple path between nodes and .
The organizers will select a starting node and an ending node (it is required that ). The unique simple path between and will be the race course. All residents will watch the race. The household at node will go to the node on the path that is closest to (i.e., minimizes ; such a node is unique). The distance is defined as the "passion value" of this household, denoted by .
Let be the average passion value over all households, defined as . The organizers consider the race "successful" if the condition is met.
Given a constant , your task is to count the number of ordered pairs such that and the race from to is "successful".
Formal Definition:
Given an undirected tree with nodes and positive edge weights. Let denote the length of the path between and . Let be the node on the simple path that is closest to node . Define . Define . Given a constant , count the number of ordered pairs such that and .
Input Format
This problem contains multiple test cases. The first line contains a positive integer , the number of test cases.
For each test case: The first line contains two integers, and . The next lines each contain three integers , representing an edge connecting nodes and with weight . It is guaranteed that the input describes a tree.
Output Format
For each test case, output a single integer on one line, representing the answer.
4
7 3
1 6 3
6 4 1
6 7 4
2 6 2
3 6 1
5 6 2
6 1
2 5 4
2 1 1
2 3 3
2 4 2
6 2 2
10 2
3 2 3
4 9 2
3 10 4
10 4 1
7 6 1
3 5 3
9 8 2
7 10 1
8 1 2
10 1
1 7 2
3 2 3
8 6 4
5 4 2
9 3 2
4 10 3
10 1 4
2 5 3
9 6 2
0
3
2
24
Hint
【Data Range】
For all test cases, it is guaranteed that:
- .
- .
This problem uses subtasks for scoring. The descriptions of the subtasks are as follows:
| Subtask | Score | |
|---|---|---|
京公网安备 11011102002149号