#C5069. Route with Sufficient Width

    ID: 48677 Type: Default 1000ms 256MiB

Route with Sufficient Width

Route with Sufficient Width

You are given a network of castles connected by bidirectional roads. Each road has an associated width and represents the maximum number of people who can simultaneously pass through. Given the number of people that need to travel, determine if there exists a path from a specified starting castle to a destination castle such that the minimum width along the path is at least the number of people.

This problem can be modeled as finding a maximum‐bottleneck path between two nodes in a graph. You are expected to use an approach similar to Dijkstra's algorithm where, instead of minimizing distance, you maximize the minimum width along the path.

Note: All roads are bidirectional. The path qualifies only if every road in the chosen path can accommodate at least p people.

inputFormat

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

  • The first line contains five integers: n m s t p, where
    • n is the number of castles.
    • m is the number of roads.
    • s is the starting castle index.
    • t is the destination castle index.
    • p is the number of people that must be accommodated.
  • The next m lines each contain three integers: u v w representing a road between castle u and castle v with a width of w.

outputFormat

Output to standard output (stdout) a single line containing either YES if it is possible to route at least p people from castle s to castle t, or NO otherwise.

## sample
4 5 1 4 7
1 2 8
1 3 10
2 3 5
2 4 7
3 4 6
YES