#K75807. Delivering Goods Without Exceeding Road Capacities

    ID: 34501 Type: Default 1000ms 256MiB

Delivering Goods Without Exceeding Road Capacities

Delivering Goods Without Exceeding Road Capacities

In this problem, you are given a network of plants connected by bidirectional roads, where each road has a certain capacity. You are also given a set of goods deliveries, each specified by a source plant, a target plant, and a weight. For each delivery, you need to find whether there exists a path from the source to the target such that the minimum capacity (i.e. the bottleneck capacity) along the path is at least the weight of the delivery. Formally, for a given path (P) consisting of edges with capacities (c_1, c_2, \dots, c_k), the bottleneck capacity is defined as (\min{c_1, c_2, \dots, c_k}). A delivery can be made if there exists a path (P) for which (\min{c_1, c_2, \dots, c_k} \ge w), where (w) is the weight of the delivery. You must determine if all deliveries can be successfully processed. If yes, output YES, otherwise output NO.

inputFormat

The input is given from standard input (stdin) and has the following format:

  • The first line contains two integers (n) and (m), where (n) is the number of plants and (m) is the number of roads.
  • Then (m) lines follow, each containing three integers (u), (v), and (c), indicating there is a bidirectional road between plant (u) and plant (v) with capacity (c).
  • The next line contains an integer (k), the number of deliveries.
  • Then (k) lines follow, each containing three integers (s_i), (t_i), and (w_i), representing a delivery request from plant (s_i) to plant (t_i) with weight (w_i).

outputFormat

Output a single line to standard output (stdout): YES if all deliveries can be made without any road being overloaded (i.e. for each delivery the path's bottleneck capacity is at least the required weight), and NO otherwise.## sample

5 6
1 2 500
2 3 600
3 4 300
4 5 400
1 3 700
2 5 200
4
1 5 200
2 4 100
3 1 300
5 2 150
YES

</p>