fork(1) download
  1. // "A delivery company has n depots numbered 0 ... n-1, connected by n-1 two-way roads so that every depot can reach the HQ at depot 0 (the road network forms a tree). Every depot except the HQ has exactly ONE package that must be driven to the HQ. Each van holds up to `seats` packages, and driving a van across ONE road costs 1 litre of fuel. Vans may combine loads: when routes meet, packages can be pooled into fewer vans.
  2.  
  3.  
  4.  
  5. // Given the roads as pairs [a, b] and the value `seats`, return the minimum total litres of fuel needed to bring every package to depot 0.
  6. // (1 <= n <= 10^5; roads.length == n-1; 1 <= seats <= 10^5.)
  7.  
  8. // Example 1:
  9. // Input: roads = [[0,1],[0,2],[0,3]], seats = 5
  10. // Output: 3
  11. // Explanation: Depots 1, 2, 3 each drive their package one road to depot 0: 1 + 1 + 1 = 3 litres.
  12.  
  13.  
  14.  
  15. // Example 2:
  16. // Input: roads = [[3,1],[3,2],[1,0],[0,4],[0,5],[4,6]], seats = 2
  17. // Output: 7
  18. // Explanation: Packages pool as they move toward 0; with 2 seats per van the total works out to 7 litres.
  19.  
  20.  
  21.  
  22. // Example 3:
  23. // Input: roads = [], seats = 1
  24. // Output: 0
  25. // Explanation: Only the HQ exists; nothing to deliver."
  26.  
  27. #include <iostream>
  28. using namespace std;
  29.  
  30. int main() {
  31. // your code goes here
  32. return 0;
  33. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty