#K71597. Maximum Bandwidth Path

    ID: 33566 Type: Default 1000ms 256MiB

Maximum Bandwidth Path

Maximum Bandwidth Path

You are given an undirected network with \(N\) nodes and \(M\) edges. Each edge connects two nodes \(u\) and \(v\) with a given bandwidth capacity \(c\). The bandwidth of a path is defined as the minimum capacity among all edges on that path, i.e., for a path \(P\):

\(\text{bandwidth}(P)=\min_{e\in P} c(e)\)

Your task is to find the maximum possible bandwidth from node \(A\) (Alice's node) to node \(B\) (Bob's node). If \(A\) and \(B\) are the same, the maximum bandwidth is considered to be inf (infinite). If no valid path exists, output 0.

inputFormat

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

N M A B
u1 v1 c1
u2 v2 c2
... (M lines in total)

where:

  • N: number of nodes (nodes are labeled from 1 to N)
  • M: number of edges
  • A: Alice's node
  • B: Bob's node
  • u, v: endpoints of an edge
  • c: bandwidth capacity of that edge

outputFormat

Output a single line to standard output (stdout) containing the maximum bandwidth from node \(A\) to node \(B\). Print inf if \(A = B\), and 0 if no path exists.

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