Skip to the code
cf.
+50 XP

#481 Maximum Upload Throughput

hard

A video platform routes uploads from an ingest server to a storage server through a network of relays. Nodes are numbered 0 to n - 1, and links[i] = [from, to, capacity] means up to capacity megabits per second can flow from from to to. Traffic can be split across many routes.

Write maxThroughput(n, links, source, sink) that returns the most megabits per second that can flow from source to sink without any link carrying more than its capacity. source and sink are different.

Example 1

Input: n = 4, links = [[0,1,3],[0,2,2],[1,2,1],[1,3,2],[2,3,3]], source = 0, sink = 3
Output: 5

Send 2 along 0 → 1 → 3, 2 along 0 → 2 → 3, and 1 along 0 → 1 → 2 → 3. Both links out of node 0 are then full.

Example 2

Input: n = 3, links = [[0,1,4]], source = 0, sink = 2
Output: 0

Nothing reaches node 2.

Constraints

  • 2 <= n <= 100
  • 0 <= links.length <= 1000
  • 1 <= capacity <= 10^5
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).