Tree
题号:NC51116
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
64bit IO Format: %lld

题目描述

Give a tree with vertices,each edge has a length(positive integer less than 1000).
Define dist(u,v)=The min distance between node and .
Give an integer ,for every pair (u,v) of vertices is called valid if and only if dist(u,v) not exceed .
Write a program that will count how many pairs which are valid for a given tree.
, ,

输入描述:

The input contains several test cases. The first line of each test case contains two integers The following  lines each contains three integers , which means there is an edge between node  and  of length .
The last test case is followed by two zeros.

输出描述:

For each test case output the answer on a single line.
示例1

输入

复制
5 4
0 1 3
0 2 1
0 3 2
2 4 1
0 0

输出

复制
8