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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| ##include "bits/stdc++.h" using namespace std;
typedef long long ll;
##define INF 0x3f3f3f3f
const int N = 105, M = 1005; int n, m, s, t, x; int maxflow; int deep[N], cur[N];
struct Edge { int v, next; int cap; } e[M << 1]; int head[M << 1], cnt;
inline void init() { mem(head, -1); cnt = maxflow = 0; }
inline void add(int u, int v, int cap) { e[cnt].v = v; e[cnt].cap = cap; e[cnt].next = head[u]; head[u] = cnt++;
e[cnt].v = u; e[cnt].cap = 0; e[cnt].next = head[v]; head[v] = cnt++; }
bool bfs() { for (int i = 0; i <= t; i++) { deep[i] = -1; cur[i] = head[i]; } queue<int> q; q.push(s); deep[s] = 0; while (!q.empty()) { int u = q.front(); q.pop(); for (int i = head[u]; ~i; i = e[i].next) { int v = e[i].v; if (deep[v] == -1 && e[i].cap) { deep[v] = deep[u] + 1; q.push(v); } } } if (deep[t] >= 0) return true; else return false; }
int dfs(int u, int mx) { int a; if (u == t) return mx; for (int i = cur[u]; ~i; i = e[i].next) { cur[u] = i; int v = e[i].v; if (e[i].cap && deep[v] == deep[u] + 1 && (a = dfs(v, min(mx, e[i].cap)))) { e[i].cap -= a; e[i ^ 1].cap += a; return a; } } return 0; }
void dinic() { int res; while (bfs()) { while (1) { res = dfs(s, INF); if (!res) break; maxflow += res; } } }
int u[M << 1], v[M << 1]; int cap[M << 1];
bool judge(double w) { init(); for (int i = 1; i <= m; i++) { add(u[i], v[i], (int)min(1.0 * x, cap[i] / w)); } dinic(); if (maxflow >= x) return true; else return false; }
void solve() { cin >> n >> m >> x; s = 1; t = n; for (int i = 1; i <= m; i++) { cin >> u[i] >> v[i] >> cap[i]; } double l = 0, r = 1e18; double ans = 0; for (int i = 0; i <= 100; i++) { double mid = (l + r) / 2; if (judge(mid)) { ans = mid; l = mid; } else { r = mid; } } cout << fixed << setprecision(10) << ans * x << endl; }
signed main() { solve(); }
|