From 4c568a403824233f6ce13f683a5f57b90d4383ef Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Wed, 21 Jul 2021 10:01:27 +0800 Subject: [PATCH] P5837 [USACO19DEC]Milk Pumping G R53757057 --- Luogu/problem/P5837/P5837.cpp | 60 +++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Luogu/problem/P5837/P5837.cpp diff --git a/Luogu/problem/P5837/P5837.cpp b/Luogu/problem/P5837/P5837.cpp new file mode 100644 index 00000000..d203d847 --- /dev/null +++ b/Luogu/problem/P5837/P5837.cpp @@ -0,0 +1,60 @@ +#include + +using namespace std; + +struct node { + int to, cost, limit; + + node() { + to = cost = limit = 0; + } + node(int _to, int _cost, int _limit) { + to = _to; + cost = _cost; + limit = _limit; + } + + bool operator<(const node& b) const { + return cost > b.cost; + } +}; + +int n, m, a, b, c, f, limit[1005], dist[1005], ans; +vector g[1005]; +bool st[1005]; + +int dijkstra(int x) { + memset(st, 0x00, sizeof(st)); + memset(dist, 0x3f, sizeof(dist)); + priority_queue q; + q.push(node(1, 0, x)); + dist[1] = 0; + while (!q.empty()) { + auto t = q.top(); + q.pop(); + if (st[t.to]) continue; + for (auto i : g[t.to]) { + if (i.limit >= x && dist[i.to] > dist[t.to] + i.cost) { + dist[i.to] = dist[t.to] + i.cost; + q.push(node(i.to, dist[i.to], x)); + } + } + st[t.to] = true; + } + return dist[n]; +} + +int main() { + cin >> n >> m; + for (int i = 1; i <= m; i++) { + cin >> a >> b >> c >> f; + limit[i] = f; + g[a].push_back(node(b, c, f)); + g[b].push_back(node(a, c, f)); + } + for (int i = 1; i <= m; i++) { + ans = max(ans, limit[i] * 1000000 / dijkstra(limit[i])); + } + cout << ans << endl; + return 0; +}