fork download
  1. /// Milk Pumping Gold USACO
  2. /// Author: PmQwerty
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. const int MAXN = 1010;
  6. const int INF = 1e9 + 7;
  7. struct Edge{
  8. int u;
  9. int w;
  10. int f;
  11. Edge(){
  12. }
  13. Edge(int u, int w, int f): u(u), w(w), f(f) {}
  14. };
  15. vector<Edge> a[MAXN];
  16. int n, m;
  17. int d[MAXN];
  18. int dijkstra(int f){
  19. priority_queue<pair<int, int>> pq;
  20. for (int i = 0; i < n; i++){
  21. d[i] = INF;
  22. }
  23. d[0] = 0;
  24. pq.push({0, 0});
  25. while (!pq.empty()){
  26. int u = pq.top().second;
  27. int w = pq.top().first;
  28. pq.pop();
  29. for (Edge v: a[u]){
  30. if (v.f < f) continue;
  31. if (d[v.u] > w + v.w){
  32. d[v.u] = w + v.w;
  33. pq.push({d[v.u], v.u});
  34. }
  35. }
  36. }
  37. return (d[n - 1] == INF ? -1 : d[n - 1]);
  38. }
  39. int main(){
  40. //freopen("pump.in", "r", stdin);
  41. //freopen("pump.out", "w", stdout);
  42. ios_base::sync_with_stdio(0);
  43. cin.tie(0);
  44. cin >> n >> m;
  45. vector<int> flows;
  46. for (int i = 1; i <= m; i++){
  47. int u, v, c, f;
  48. cin >> u >> v >> c >> f;
  49. flows.push_back(f);
  50. u--;
  51. v--;
  52. a[u].push_back(Edge(v, c, f));
  53. a[v].push_back(Edge(u, c, f));
  54. }
  55. int ans = -1;
  56. for (int f: flows){
  57. int cur = dijkstra(f);
  58. if (cur == -1) continue;
  59. double r = f * 1.0 / cur;
  60. ans = max(ans, (int)(r * 1e6));
  61. }
  62. cout << ans << '\n';
  63. }
  64.  
Success #stdin #stdout 0s 5280KB
stdin
3 2
2 1 2 4
2 3 5 3
stdout
428571