Explanation
The larger the denominator, the smaller the result will be. We also want to minimize the cost of the path. This hints at a shortest-path problem. Due to the low number of junction points, we can fix the minimum flow rate and search for the lowest cost path we could take.
Implementation
Time Complexity:
// Created by Qi Wangimport java.io.*;import java.util.*;public class pump {static int N;static int M;static List<Node>[] adjList;static boolean[] vist;static int[] costs;
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!