题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314

题意:

给n个点,及m根pipe,每根pipe用来流躺液体的,单向的,每时每刻每根pipe流进来的物质要等于流出去的物质,要使得m条pipe组成一个循环体,里面流躺物质。

并且满足每根pipe一定的流量限制,范围为[Li,Ri].即要满足每时刻流进来的不能超过Ri(最大流问题),同时最小不能低于Li。

求的是最大流。

很久之前就看了带上下界的网络流,一直没看懂,以为刘汝佳的书上写错了,哈哈~~~

建图:

修改成普通的网络流,但是要保证流量守恒,那么,ss到v的容量,u到tt的容量为 b,而且,要这些附加的边上的流必须满载。

然后题目要求最大的流,那么要把这个可行流找出来,这样,我建边的时候,先不加ss,tt的边,

这样,可行流就在edge[i*2]的地方。

 #include <bits/stdc++.h>

 using namespace std;

 #define inf 0x3f3f3f3f

 const int maxn = ;

 //int low[maxn],in[maxn],out[maxn];

 struct Edge
{
int from,to,cap,flow;
}; struct Dinic
{
int n,m,s,t;
vector<Edge> edge;
vector<int> G[maxn];
bool vis[maxn];
int d[maxn];
int cur[maxn]; void init()
{
for(int i=;i<maxn;i++)
G[i].clear();
edge.clear();
memset(d,,sizeof(d));
memset(vis,,sizeof(vis));
memset(cur,,sizeof(cur));
} void AddEdge (int from,int to,int cap)
{
edge.push_back((Edge){from,to,cap,});
edge.push_back((Edge){to,from,,});
m = edge.size();
G[from].push_back(m-);
G[to].push_back(m-);
} bool BFS()
{
memset(vis,,sizeof(vis));
queue<int> Q;
Q.push(s);
d[s] = ;
vis[s] = ;
while(!Q.empty())
{
int x = Q.front();
Q.pop();
for(int i=; i<G[x].size(); i++)
{
Edge & e = edge[G[x][i]];
if(!vis[e.to]&&e.cap>e.flow)
{
vis[e.to] = ;
d[e.to] = d[x] + ;
Q.push(e.to);
}
}
}
return vis[t];
} long long DFS(int x,int a)
{
if(x==t||a==) return a;
long long flow = ,f;
for(int & i = cur[x]; i<G[x].size(); i++)
{
Edge & e = edge[G[x][i]];
if(d[x] + ==d[e.to]&&(f=DFS(e.to,min(a,e.cap-e.flow)))>)
{
e.flow +=f;
edge[G[x][i]^].flow -=f;
flow +=f;
a-=f;
if(a==) break;
}
}
return flow;
} int Maxflow (int s,int t) {
this->s = s;this->t = t;
int flow = ;
while(BFS()) {
memset(cur,,sizeof(cur));
flow+=DFS(s,inf);
}
return flow;
} void print(int cnt) {
for(int i=;i<cnt;i++)
printf("%d\n",edge[i*].flow+edge[G[][i]].flow);
} }sol; int main()
{
int t;
scanf("%d",&t);
while(t--) {
int n,m;
scanf("%d%d",&n,&m);
int low[maxn],uu[maxn],vv[maxn];
int sum = ;
sol.init();
for(int i=;i<m;i++) {
int u,v,b,c;
scanf("%d%d%d%d",&u,&v,&b,&c);
low[i] = b;
uu[i] = u;
vv[i] = v;
sol.AddEdge(u,v,c-b);
sum+=b;
// out[u] +=low[i];
// in[v] +=low[i];
// sol.AddEdge(0,v,b);
// sol.AddEdge(u,n+1,b);
} for(int i=;i<m;i++) {
sol.AddEdge(,vv[i],low[i]);
sol.AddEdge(uu[i],n+,low[i]);
} int maxflow = sol.Maxflow(,n+);
if(sum!=maxflow)
puts("NO");
else {
puts("YES");
// for(int i=0;i<sol.G[0].size();i++) {
// printf("%d\n",sol.edge[sol.G[0][i]].flow);
// }
sol.print(m);
}
}
return ;
}

ZOJ 2314 Reactor Cooling 带上下界的网络流的更多相关文章

  1. ZOJ 2314 - Reactor Cooling - [无源汇上下界可行流]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2314 The terrorist group leaded by ...

  2. ZOJ 2314 Reactor Cooling(无源汇有上下界可行流)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2314 题目大意: 给n个点,及m根pipe,每根pipe用来流躺 ...

  3. zoj 2314 Reactor Cooling (无源汇上下界可行流)

    Reactor Coolinghttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314 Time Limit: 5 Seconds ...

  4. ZOJ 2314 Reactor Cooling(无源汇上下界网络流)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2314 题意: 给出每条边流量的上下界,问是否存在可行流,如果存在则输出. ...

  5. Zoj 2314 Reactor Cooling(无源汇有上下界可行流)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314 题意:    给n个点,及m根pipe,每根pipe用来流躺液体的,单向 ...

  6. [ZOJ2341]Reactor Cooling解题报告|带上下界的网络流|无源汇的可行流

    Reactor Cooling The terrorist group leaded by a well known international terrorist Ben Bladen is bul ...

  7. ZOJ 2314 Reactor Cooling

    Reactor Cooling Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origina ...

  8. zoj 2314 Reactor Cooling 网络流

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314 The terrorist group leaded by a ...

  9. 【zoj2314】Reactor Cooling 有上下界可行流

    题目描述 The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nuc ...

随机推荐

  1. SQL 行转列的两种做法

    if object_id('tb')is not null drop table tbGocreate table tb(姓名 varchar(10),课程 varchar(10),分数 int)in ...

  2. oracle service name connect

    oracle service name connect dest_ip=100.100.100.100 dest_port= dest_dbname=server_name connect=" ...

  3. 企业生产环境不同业务linux系统分区方案

    转自:http://edu.51cto.com/lession/id-11842.html

  4. mgo02_mongodb启动警告处理

    ** WARNING: Access control is not enabled for the database. 原因分析:新版本的MongDB增加了安全性设计,推荐用户创建使用数据库时进行验证 ...

  5. java——并查集 UnionFind

    时间复杂度: O(log*n),近乎是O(1)级别的 UnionFind 接口: public interface UF { int getSize(); boolean isConnected(in ...

  6. Checkstyle的配置详解

    Checkstyle是一款检查java程序代码样式的工具,可以有效的帮助我们检视代码以便更好的遵循代码编写标准,特别适用于小组开发时彼此间的样式规范和统一.Checkstyle提供了高可配置性,以便适 ...

  7. SQL Server Reporting Service(SSRS) 第六篇 SSRS 部署总结

    前段时间完成了第一批次SSRS报表的开发,本来以为大功已经告成,结果没有想到在整个发布与部署过程中还是遇到了很多的问题,现将这些问题一一列举出来,希望对以后能够有所启发! 1. 关于数据源与数据集的发 ...

  8. Dev Express Report 学习总结(四)Dev Express 动态生成XRTable使用总结

    1. XRTableCell常见属性  XRTableCell xrTableCell = new XRTableCell(); A. 字体及字体大小 xrTableCell.Font = new S ...

  9. Hive学习(一)

    https://www.cnblogs.com/qingyunzong/p/8707885.html http://www.360doc.com/content/16/1006/23/15257968 ...

  10. [转]jQuery实现图片轮播效果,jQuery实现焦点新闻

    本文转自:http://blog.csdn.net/tsyj810883979/article/details/8986157 效果图: 实现代码: <!DOCTYPE html> < ...