#abc250h. Ex - Trespassing Takahashi

Ex - Trespassing Takahashi

Score : 600600 points

问题描述

NN 个编号为 11NN 的点,以及 MM 条道路。第 ii 条(1iM1 \leq i \leq M)道路在点 aia_i 和点 bib_i 之间双向连接,并且需要 cic_i 分钟通过。使用一些数量的道路可以从任意一个点到达另一个点。在点 1,,K1,\ldots, K 上有房子。

对于 i=1,,Qi=1,\ldots,Q,解决以下问题:

高桥当前位于编号为 xix_i 的房子处,他想要前往编号为 yiy_i 的房子处。
自从他上次睡觉后经过了 tit_i 分钟,他就无法再继续移动。
他只能在有房子的点上睡觉,但可以任意次数地进行休息。
如果他可以从点 xix_i 到达点 yiy_i,则输出 Yes;否则,输出 No

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN points numbered 11 through NN, and MM roads. The ii-th (1iM1 \leq i \leq M) road connects Point aia_i and Point bib_i bidirectionally and requires cic_i minutes to pass through. One can travel from any point to any other point using some number of roads. There is a house on Points 1,,K1,\ldots, K.

For i=1,,Qi=1,\ldots,Q, solve the following problem.

Takahashi is currently at the house at Point xix_i and wants to travel to the house at Point yiy_i.
Once tit_i minutes have passed since his last sleep, he cannot continue moving anymore.
He can get sleep only at a point with a house, but he may do so any number of times.
If he can travel from Point xix_i to Point yiy_i, print Yes; otherwise, print No.

Constraints

  • 2KN2×1052 \leq K \leq N \leq 2 \times 10^5
  • $N-1 \leq M \leq \min (2 \times 10^5, \frac{N(N-1)}{2})$
  • 1ai<biN1 \leq a_i \lt b_i \leq N
  • If iji \neq j, then (ai,bi)(aj,bj)(a_i,b_i) \neq (a_j,b_j).
  • 1ci1091 \leq c_i \leq 10^9
  • One can travel from any point to any other point using some number of roads.
  • 1Q2×1051 \leq Q \leq 2 \times 10^5
  • 1xi<yiK1 \leq x_i \lt y_i \leq K
  • 1t1tQ10151 \leq t_1 \leq \ldots \leq t_Q \leq 10^{15}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM KK

a1a_1 b1b_1 c1c_1

\vdots

aMa_M bMb_M cMc_M

QQ

x1x_1 y1y_1 t1t_1

\vdots

xQx_Q yQy_Q tQt_Q

Output

Print QQ lines. The ii-th line should contain the answer for the ii-th problem.

Sample Input 1

6 6 3
1 4 1
4 6 4
2 5 2
3 5 3
5 6 5
1 2 15
3
2 3 4
2 3 5
1 3 12

Sample Output 1

No
Yes
Yes

In the 33-rd problem, it takes no less than 1313 minutes from Point 11 to reach Point 33 directly. However, he can first travel to Point 22 in 1212 minutes, get sleep in the house there, and then travel to Point 33. Thus, the answer is Yes.

update @ 2024/3/10 10:42:13