P26939 [AtCoder] Shortest Path
NOI
题目描述

Problem Description

In the country of AtCoder, there are $ N $ cities numbered from $ 1 $ to $ N $ and $ N-1 $ roads numbered from $ 1 $ to $ N-1 $. All cities can travel to each other.
Road $ i $ connects city $ a_i $ and city $ b_i $ bidirectionally with a length of $ c_i $ kilometers.

Given a positive integer $ X $, determine if there exists a pair of distinct cities $ (i,j) $ that satisfies the following condition and output Yes if it exists, otherwise output No.

  • The length of the shortest path when traveling from city $ i $ to city $ j $ using the roads is $ X $ kilometers.

Input Format

The input is given from the standard input in the following format:

$ N $ $ X $ $ a_1 $ $ b_1 $ $ c_1 $ $\vdots$ $ a_{N-1} $ $ b_{N-1} $ $ c_{N-1} $

Output Format

Output Yes if there exists a pair of cities that satisfies the condition, otherwise output No.

Sample Input and Output

Sample Input #1

3 5
1 2 3
1 3 2

Sample Output #1

Yes

Sample Input #2

3 4
1 2 3
1 3 2

Sample Output #2

No

Sample Input #3

10 15
3 8 3
5 9 3
6 7 1
7 8 1
2 8 5
2 4 5
4 9 3
1 4 5
1 10 2

Sample Output #3

Yes

Notes/Hints

Constraints

  • $2 \leq N \leq 3000$
  • $1 \leq a_i < b_i \leq N$
  • All cities can travel to each other.
  • $1 \leq c_i < 10^5$
  • $1 \leq X \leq 10^9$
  • All values in the input are integers.

Sample Explanation 1

The shortest path from city $ 2 $ to city $ 3 $ is $ 5 $ kilometers, which satisfies the condition. Therefore, output Yes.

Sample Explanation 2

There is no pair of cities with a shortest path length of $ 4 $ kilometers. Therefore, output No.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 5 1 2 3 1 3 2
样例输出
Yes