#K15801. Taco: Limited Energy Path Query

    ID: 24437 Type: Default 1000ms 256MiB

Taco: Limited Energy Path Query

Taco: Limited Energy Path Query

You are given an undirected weighted graph with n nodes and m edges. Each edge connects two nodes and has a certain energy cost. In addition, you are given q queries. Each query is described by three integers: a starting node s, a target node t, and an energy limit E.

Your task is to determine whether there exists a path from s to t such that:

  • Every edge used in the path has an energy cost not exceeding E.
  • The total sum of the energy costs along the path is at most E (i.e. the cumulative energy cost is \(\le E\)).

If both conditions are satisfied the output for that query should be "Yes"; otherwise, the answer should be "No".

Note: The graph is undirected and the same edge can be traversed in both directions.

inputFormat

The input is read from stdin and has the following format:

n m q
u1 v1 w1
u2 v2 w2
... (m edges in total)

s1 t1 E1 s2 t2 E2 ... (q queries in total)

</p>

Where:

  • n is the number of nodes.
  • m is the number of edges.
  • q is the number of queries.
  • Each of the following m lines describes an edge between nodes u and v with an energy cost w.
  • Each of the last q lines describes a query with a starting node s, a target node t, and an energy limit E.

outputFormat

For each query, print a single line to stdout that contains either "Yes" or "No" depending on whether it is possible to travel from s to t under the given constraints.

## sample
5 5 4
1 2 3
1 3 4
2 4 5
3 4 3
4 5 2
1 4 6
1 5 10
2 5 7
3 2 4
No

Yes Yes No

</p>