Latency Threshold Queries
A datacenter has n hosts, numbered from 1 to n, connected by m physical links. The i-th
link joins hosts u_i and v_i and has a measured latency w_i. Links can be used in either
direction, there can be several links between the same pair of hosts, and a link may even join a
host to itself (a loopback).
The SLA team runs compliance checks of the form: can host u reach host v using only links
whose latency is strictly less than some threshold L? A host can always reach itself, even
with no links at all. Checks may repeat, and the same pair of hosts may be asked about with
different thresholds.
You are given all the links once, then q independent checks. For each check (u, v, L), decide
whether u and v are connected in the subgraph formed by only the links with latency < L.
Input
The first line contains three integers n, m and q (1 ≤ n ≤ 10^5, 0 ≤ m ≤ 2·10^5,
1 ≤ q ≤ 2·10^5): the number of hosts, the number of links, and the number of checks.
Each of the next m lines contains three integers u_i, v_i and w_i
(1 ≤ u_i, v_i ≤ n, 1 ≤ w_i ≤ 10^9): a link between hosts u_i and v_i with latency w_i.
Each of the next q lines contains three integers u_i, v_i and L_i
(1 ≤ u_i, v_i ≤ n, 1 ≤ L_i ≤ 10^9 + 1): a check asking whether u_i and v_i are connected using
only links with latency strictly less than L_i.
Output
Print q lines. The i-th line must be YES if the i-th check's hosts are connected using
only links with latency < L_i, and NO otherwise.
Notes
In the first example, sorting the links by latency gives (2,3,3), (1,2,5), (1,3,8),
(4,5,10).
- Check
1 3 4only allows the link of latency3, so1and3are not yet connected:NO. - Check
1 3 9allows every link except(4,5,10), joining1,2and3:YES. - Check
4 5 10excludes(4,5,10)itself, since the latency must be strictly less than10:NO. - Check
4 5 11allows(4,5,10):YES. - Check
2 2 1asks whether host2reaches itself, which is always true, even with a threshold of1and no usable links:YES.
In the second example, (3,3,5) is a loopback and the two copies of (1,2,2) are parallel links;
neither changes which hosts are reachable from which. The check 1 3 7 excludes the link
(2,3,7) (not strictly below 7), so 1 and 3 are not yet connected, but raising the threshold
to 8 includes it and connects them.