Directory
- 2016ACM/ICPC Asia Qingdao Station Coding Contest fee flow
- Title Description
- Test instructions (Blogger's Ghost Animal translator):
- Analysis:
- Code
2016ACM/ICPC Asia Qingdao Station Coding Contest fee flow Title description
Title Description A Coding contest would be held in this university, in a huge playground. The whole playground would is divided into N blocks, and there would is M directed paths linking these blocks. The i-th path goes from the ui-th block to the vi-th block. Your task is to solve the lunch issue. According to the arrangement, there is SI competitors in the i-th block. Limited to the size of table, bi bags of lunch including breads, sausages and milk would is put in the i-th block. As a result, some competitors need to move to another block to access lunch. However, the playground is temporary, as a result there would being so many wires on the path. For the i-th path, the wires has been stabilized at? RST and the. RST competitor who Walker through it would don't break th E wires. Since then, however, when a person go through the i?th path, there are a chance of pi to touch the wires and a?ect the Whol E Networks. Moreover, to protect these wires, no more than CI competitors is allowed to walkThrough the i-th path. Now your need to nd a-to-all competitors to get their lunch, and minimize the possibility of the network crashing. Input description: the. RST line of input contains a integer t which is the number of the test cases. Then T test cases follow. For each test case, the. RST line consists of integers N (n≤100) and M (m≤5000). Each of the next N lines contains, integers si and bi (si,bi≤200). Each of the next M lines contains three integers ui,vi and CI (ci≤100) and a? Oat-point number pi (0 < pi < 1). It is guaranteed this there is at least one-to-let every competitor have lunch. Output Description: For each turn in each case, output the minimum possibility, the networks would break. Round it to 2 digits.
Test instructions (Blogger's Ghost Animal translator):
There are n points, M-bars, each point has a \ (a_i\) competitor, and \ (b_i\) The food that everyone wants to eat, can pass some path. Each path wire has \ (p_i\) the probability of a bad, the first person must not be bad. Ask how to walk everyone can get food, the probability of cutting bad is the least.
Analysis:
First, this input U-v cost \ (c_i\) probability \ (p_i\) cost flow input is still very good-looking out.
- Source points per point (1~n) number of traffic, cost 0
- Each point (1~n) connected to the meeting point, traffic food, fee 0
"1"
This problem becomes the lowest probability of the cost representation of the source point to the meeting point. The probability count of all the topics is multiplication, and the cost flow is additive. This needs to be converted to log in the form of log (AB) = log (a) + log (b) So the result of the final request for an exp (x) is good.
"2"
2nd, the probability of bad you do not know the exact path of the edge is broken. If the problem is turned into the biggest not bad probability, it becomes the path of each road is not bad, then the probability is unified.
So
For U->v capacity C, the probability p
Build Edge u->v, Flow C, cost-log (1-P)
PS: The difference between maximum flow and minimum cost maximum flow is the addition of the edge plus a symbol, the result is reversed.
"3"
Then there is a third problem: the first person will not be sprayed bad, then we can remove the edge. This is a small problem compared to the front.
Write, code SPFA in a place did not write eps,tle do not know why, and then the floating-point cost flow notice in the board int the change to the whole change.
Code
2016ACM/ICPC Asia Qingdao Station Coding Contest cost flow # include <bits/stdc++.h> using namespace std; Const double EPS = 1e-4; struct MCMF {static const int MAXN = 200; static const int MAXM = 10000; static const int INF = 1e9 + 7; static const int inf0x3f = 0X3F3F3F3F; int n, M, First[maxn], s, T, sign; Double DIST[MAXN]; int INQ[MAXN], PRE[MAXN], INCF[MAXN]; int max_flow; Double min_cost; struct Edge {int to, cap, next; Double cost; } EDGE[MAXM * 4]; void init (int l, int r, int ss, int tt) {memset (First,-1, sizeof (first)); s = ss, T = TT, sign = 0; Max_flow = Min_cost = 0; } void Add_edge (int u, int v, int cap, double cost) {edge[sign].to = V, edge[sign].cap = cap, edge[sign].cost = Cost; Edge[sign].next = First[u], first[u] = sign++; edge[sign].to = u, edge[sign].cap = 0, edge[sign].cost =-cost; Edge[sign].next = First[v], first[v] = sign++; } bool SPFA (int s, int t){for (int i = 0; i < MAXN; i++) {dist[i] = INF; Inq[i] = 0; Pre[i] =-1; } queue<int>que; Que.push (s), inq[s] = 1, dist[s] = 0; Incf[s] = inf0x3f; while (!que.empty ()) {Int. now = Que.front (); Que.pop (); Inq[now] = 0; for (int i = first[now]; ~i; i = edge[i].next) {int to = edge[i].to, Cap = Edge[i].cap; Double cost = edge[i].cost; Don't add EPS t anymore? if (Cap > 0 && dist[to] > Dist[now] + cost + EPS) {Dist[to] = Dist[now] + cost; Incf[to] = min (Incf[now], cap); Pre[to] = i; if (!inq[to]) {Que.push (to); Inq[to] = 1; }}}} return Fabs (Dist[t]-INF) > EPS; } void Update (int s, int t) {int x = t; while (x! = s) {int pos = pre[x]; Edge[pos].cap-= incf[t]; Edge[pos ^ 1].cap + = Incf[t]; x = edge[pos ^ 1].to; } Max_flow + = Incf[t]; Min_cost + = dist[t] * Incf[t]; } void Mincostmaxflow (int s, int t) {while (SPFA (s, t)) {update (S, t); }}} CWL; int main () {int T, n, M; scanf ("%d", &t); while (t--) {scanf ("%d%d", &n, &m); Cwl.init (0, n + 1, 0, n + 1); for (int i = 1; I <= n; i++) {int A, B; scanf ("%d%d", &a, &b); if (a) {Cwl.add_edge (0, I, a, 0); } if (b) {Cwl.add_edge (i, n + 1, b, 0); }} for (int i = 1; I <= m; i++) {int u, V, cap; Double cost; scanf ("%d%d%d%lf", &u, &v, &cap, &cost); Cost =-log (1-cost); Cwl.add_edge (U, V, 1, 0); Cwl.add_edge (U, V, cap-1, cost); } cwl.mincostmaxflow (0, n + 1); printf ("%.2f\n", 1-exp (-cwl.min_cost)); } return 0;}
2016ACM/ICPC Asia Qingdao station Coding Contest fee flow