#C4575. Taco Path Query
Taco Path Query
Taco Path Query
You are given a weighted undirected graph consisting of N stones (vertices) and M magical paths (edges). Each magical path connects two stones and has an associated energy value. You are also given Q queries. Each query consists of three integers U, V, and W: you must determine whether there exists a simple path (i.e. no stone is visited more than once) from stone U to stone V such that the total sum of the energies along the path is at least W.
The energy sum along a path is calculated as:
[ \sum_{(i,j) \in path} E_{ij} \geq W ]
If such a path exists, print YES
, otherwise, print NO
.
inputFormat
The first line contains three space-separated integers: N (number of stones), M (number of magical paths), and Q (number of queries).
The next M lines each contain three space-separated integers: A B E
, representing a magical path between stone A and stone B with energy value E.
The next Q lines each contain three space-separated integers: U V W
, representing a query asking whether there is a path from stone U to stone V whose total magical energy is at least W.
outputFormat
For each query, output a single line containing YES
if such a path exists, and NO
otherwise.
6 7 3
1 2 4
2 3 5
3 4 10
4 5 1
5 6 3
1 6 7
2 5 9
1 5 15
2 6 8
4 1 10
NO
YES
YES
</p>