0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

P5837 [USACO19DEC]Milk Pumping G

R53757057
This commit is contained in:
Baoshuo Ren 2021-07-21 10:01:27 +08:00 committed by Baoshuo Ren
parent d7400ec95d
commit 4c568a4038
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,60 @@
#include <bits/stdc++.h>
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<node> g[1005];
bool st[1005];
int dijkstra(int x) {
memset(st, 0x00, sizeof(st));
memset(dist, 0x3f, sizeof(dist));
priority_queue<node> 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;
}