Problem Description 
A coding contest will be held in this university, in a huge playground. The whole playground would be divided into N blocks, and there would be M directed paths linking these blocks. The i-th path goes from the u_i-th block to the v_i-th block. Your task is to solve the lunch issue. According to the arrangement, there are s_i competitors in the i-th block. Limited to the size of table, b_i bags of lunch including breads, sausages and milk would be 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 be so many wires on the path. 
For the i-th path, the wires have been stabilized at first and the first competitor who walker through it would not break the wires. Since then, however, when a person go through the i - th path, there is a chance of p_i to touch 
the wires and affect the whole networks. Moreover, to protect these wires, no more than c_i competitors are allowed to walk through the i-th path. 
Now you need to find a way for all competitors to get their lunch, and minimize the possibility of network crashing.

Input 
The first line of input contains an integer t which is the number of test cases. Then t test cases follow. 
For each test case, the first line consists of two integers N (N ≤ 100) and M (M ≤ 5000). Each of the next N lines contains two integers si and b_i (s_i , b_i ≤ 200). 
Each of the next M lines contains three integers u_i , v_i and c_i(c_i ≤ 100) and a float-point number p_i(0 < p_i < 1). 
It is guaranteed that there is at least one way to let every competitor has lunch.

Output 
For each turn of each case, output the minimum possibility that the networks would break down. Round it to 2 digits.

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double EPS = 1.0e-8;
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int maxm = ;
//next_permutation
int level[];
int Si, Ei, Ci;
struct Edge
{
int from, to, cap, flow;
double cost;
Edge() {}
Edge(int f, int t, int c, int fl, double co): from(f), to(t), cap(c), flow(fl), cost(co) {}
};
struct MCMF
{
int n, m, s, t;
vector<Edge>edges;
vector<int>g[maxn];
bool inq[maxn];
double d[maxn];
int p[maxn];
int a[maxn];
void init(int n, int s, int t)
{
this->n = n;
this->s = s;
this->t = t;
edges.clear();
for (int i = ; i <= n; i++)
{
g[i].clear();
}
}
void AddEdge(int from, int to, int cap, double cost)
{
edges.push_back(Edge(from, to, cap, , cost));
edges.push_back(Edge(to, from, , , -cost));
m = edges.size();
g[from].push_back(m - );
g[to].push_back(m - );
}
bool BellmanFord(int &flow, double &cost)
{
for (int i = ; i <= n; i++)
{
d[i] = inf;
}
memset(inq, , sizeof(inq));
d[s] = , a[s] = inf, inq[s] = , p[s] = ;
queue<int>q;
q.push(s);
while (!q.empty())
{
int u = q.front();
q.pop();
inq[u] = ;
for (int i = ; i < g[u].size(); i++)
{
Edge &e = edges[g[u][i]];
if (e.cap > e.flow && d[e.to] > d[u] + e.cost + eps)
{
d[e.to] = d[u] + e.cost;
p[e.to] = g[u][i];
a[e.to] = min(a[u], e.cap - e.flow);
if (!inq[e.to])
{
q.push(e.to);
inq[e.to] = ;
}
}
}
}
if (d[t] == inf)
{
return false;
}
flow += a[t];
cost += a[t] * d[t];
int u = t;
while (u != s)
{
edges[p[u]].flow += a[t];
edges[p[u] ^ ].flow -= a[t];
u = edges[p[u]].from;
}
return true;
}
double Min_cost(int &flow, double &cost)
{
flow = , cost = ;
while (BellmanFord(flow, cost));
return cost;
}
} mc;
int main()
{
int time;
scanf("%d", &time);
while (time--)
{ int n, m;
int a, b;
cin >> n >> m;
int s = ;
int t = * n + ;
mc.init(n * + , s, t);
for (int i = ; i <= n; i++)
{
scanf("%d %d", &a, &b);
//cin >> a >> b;
if (a == b)
{
continue;
}
else
{
if (a > b)
{
mc.AddEdge(s, i, a - b, );
}
else
{
mc.AddEdge(i, t, b - a, );
}
}
}
int u, v, c;
double p;
for (int i = ; i <= m; i++)
{
scanf("%d %d %d %lf", &u, &v, &c, &p);
//cin >> u >> v >> c >> p;
p = -log( - p);
if (c == )
{
continue;
}
else if (c == )
{
mc.AddEdge(u, v, , );
}
else
{
mc.AddEdge(u, v, , );
mc.AddEdge(u, v, c - , p);
}
}
int flow = ;
double cost = ;
cost = mc.Min_cost(flow, cost);
cost = exp(-cost);
printf("%.2f\n", - cost);
}
}

HDU 5988 Coding Contest 最小费用流 cost->double的更多相关文章

  1. HDU 5988.Coding Contest 最小费用最大流

    Coding Contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  2. HDU 5988 Coding Contest(最小费用最大流变形)

    Problem DescriptionA coding contest will be held in this university, in a huge playground. The whole ...

  3. HDU 5988 Coding Contest(费用流+浮点数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5988 题目大意: 给定n个点,m条有向边,每个点是一个吃饭的地方,每个人一盒饭.每个点有S个人,有B盒 ...

  4. HDU 5988 Coding Contest(浮点数费用流)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5988 题意:在acm比赛的时候有多个桌子,桌子与桌子之间都有线路相连,每个桌子上会有一些人和一些食物 ...

  5. HDU - 5988The 2016 ACM-ICPC Asia Qingdao Regional ContestG - Coding Contest 最小费用流

    很巧妙的建边方式 题意:有n个区域,每个区域有一些人数si和食物bi,区域之间有m条定向路径,每条路径有人数通过上限ci.路径之间铺了电线,每当有人通过路径时有pi的概率会触碰到电线,但是第一个通过的 ...

  6. Coding Contest(费用流变形题,double)

    Coding Contest http://acm.hdu.edu.cn/showproblem.php?pid=5988 Time Limit: 2000/1000 MS (Java/Others) ...

  7. HDU5988/nowcoder 207G - Coding Contest - [最小费用最大流]

    题目链接:https://www.nowcoder.com/acm/contest/207/G 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5988 ...

  8. hdu-5988 Coding Contest(费用流)

    题目链接: Coding Contest Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Ot ...

  9. 2016青岛区域赛.Coding Contest(费用流 + 概率计算转换为加法计算)

    Coding Contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

随机推荐

  1. Linux shell - 找到进程pid,然后杀掉(jps, grep, awk)

    在应用服务器上,启动一个应用程序F3后,一直挂着,如果想要关闭它话,可以使用jps找到它的pid,然后,使用kill命令杀掉这个pid,例如: $> jps 17337 Jps 6660 Mai ...

  2. CentOS关闭系统不必要的端口

    注:以下所有操作均在CentOS 7.2 x86_64位系统下完成. 1)首先查看当前系统开放的端口号: # netstat -tlnup Active Internet connections (o ...

  3. java基础--继承、实现、依赖、关联、聚合、组合的联系与区别

    继承 指的是一个类或者接口继承另一个类或者接口,而且可以增加自己的新功能. 实现 指的是一个class类实现interface接口. 依赖 简单说,就是一个类中的方法用到了另一个类,一般依赖关系在ja ...

  4. AAAI 2018 分析

    AAAI 2018 分析 word embedding Learning Sentiment-Specific Word Embedding via Global Sentiment Represen ...

  5. eclipse导入工程

    一般项目配置信息完全可直接导入,即import 如果缺失.project等文件,eclipse无法识别,则将工程拷贝到工作空间目录下,在eclipse中新建一个同名工程即可

  6. 2018 icpc 沈阳

    https://codeforces.com/gym/101955 J 签到 #include<iostream> #include<cstring> #include< ...

  7. Linux_系统进程管理

    目录 目录 进程管理 进程管理的指令 查看进程ps指令 pgreppidof指令查pid lsof查看系统中的进程 nice指令修改进程的nice值 kill指令结束进程 top系统进程管理器任务管理 ...

  8. Unity Ray 射线

    射线:射线是3D世界一个向一个方向发射的一条无终点的线,在发射轨迹中与其他物体发生碰撞时,它将停止发射. 用途:射线范围比较广,多用于碰撞检测(如:子弹飞行是否击中目标).角色移动等. Ray是一个结 ...

  9. awk结合数组统计

    1.统计用户登录类型 #!/bin/bashdeclare -A  shells (定义关联数组shells)while read ll   (读取/etc/passwd,ll为变量) dotype= ...

  10. 梳理检测论文-Refinement Neural Network

    Single-Shot Refinement Neural Network for Object Detection 目录 1. motivation 2. RefineDet 解析(Network ...