-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13010-galactic_taxes.cpp
More file actions
65 lines (52 loc) · 1.27 KB
/
Copy path13010-galactic_taxes.cpp
File metadata and controls
65 lines (52 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
int N, M;
double dist[1001];
vector<vector<pair<int, pii>>> graph;
double dijkstra(double t) {
fill(dist, dist + N, 1e10);
priority_queue<pdi, vector<pdi>, greater<pdi>> q;
q.push({0, 0});
dist[0] = 0;
while (!q.empty()) {
auto [_, u] = q.top();
q.pop();
for (auto& [v, weight] : graph[u]) {
auto [a, b] = weight;
double alt = dist[u] + (a * t + b);
if (alt < dist[v]) {
dist[v] = alt;
q.push({alt, v});
}
}
}
return dist[N - 1];
}
int main() {
while (scanf("%d %d", &N, &M) == 2) {
graph.assign(N, vector<pair<int, pii>>());
while (M--) {
int source, target, a, b;
scanf("%d %d %d %d", &source, &target, &a, &b);
source--;
target--;
graph[source].push_back({target, {a, b}});
graph[target].push_back({source, {a, b}});
}
double left = 0;
double right = 60 * 24;
int iters = 80;
while (iters--) {
double third = (right - left) / 3;
double t1 = left + third;
double t2 = right - third;
if (dijkstra(t1) < dijkstra(t2))
left = t1;
else
right = t2;
}
printf("%0.5f\n", dijkstra(left));
}
}