1 条题解
-
0
牛奶泵(Milk Pumping G) 题解
思路分析
按题目要求使用对应数据结构与算法模拟/递推求解,注意数据范围边界与时间复杂度。
参考代码
#include <iostream> #include <vector> #include <queue> #include <algorithm> using namespace std; struct Edge { int to, cost, flow; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; if (!(cin >> n >> m)) return 0; vector<vector<Edge>> adj(n + 1); vector<int> flows; for (int i = 0; i < m; ++i) { int u, v, c, f; cin >> u >> v >> c >> f; adj[u].push_back({v, c, f}); adj[v].push_back({u, c, f}); flows.push_back(f); } sort(flows.begin(), flows.end()); flows.erase(unique(flows.begin(), flows.end()), flows.end()); const long long INF = (1LL << 58); long long best = 0; for (int f_lim : flows) { vector<long long> dist(n + 1, INF); priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq; dist[1] = 0; pq.push({0, 1}); while (!pq.empty()) { auto [d, u] = pq.top(); pq.pop(); if (d != dist[u]) continue; if (u == n) break; for (const auto& e : adj[u]) { if (e.flow < f_lim) continue; if (d + e.cost < dist[e.to]) { dist[e.to] = d + e.cost; pq.push({dist[e.to], e.to}); } } } if (dist[n] < INF) { best = max(best, (1000000LL * f_lim) / dist[n]); } } cout << best << "\n"; return 0; }
- 1
信息
- ID
- 8798
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者