HDU 3917 Road constructions(最小割---最大权闭合)
题目地址:HDU 3917
这题简直神题意。。。
题目本身就非常难看懂不说。。即使看懂了。也对这题意的逻辑感到无语。。。无论了。。
就依照那题意上说的做吧。。。
题意:给你n个城市,m个公司。若干条可能要建设的道路,每条有向道路须要花费,还有负责建设这条道路的公司编号,假设要建设ab道路。那么负责这条道路的公司须要建设完它负责的全部道路。并且对负责道路bx(x随意)的公司相同要求,以此类推。
每一个公司还要交税。问最多能收多少税。
依照题意来的话。相当于某些公司对某些公司有依赖性。终于的利润==收的税-建设道路的花费。所以是一个最大权闭合模型。
代码例如以下:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
const int INF=0x3f3f3f3f;
int head[6000], cnt, source, sink, nv, val[6000];
int d[6000], num[6000], pre[6000], cur[6000];
struct node
{
int u, v, cap, next;
} edge[1000000];
void add(int u, int v, int cap)
{
edge[cnt].v=v;
edge[cnt].cap=cap;
edge[cnt].next=head[u];
head[u]=cnt++; edge[cnt].v=u;
edge[cnt].cap=0;
edge[cnt].next=head[v];
head[v]=cnt++;
}
void bfs()
{
memset(d,-1,sizeof(d));
memset(num,0,sizeof(num));
queue<int>q;
q.push(sink);
d[sink]=0;
num[0]=1;
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=head[u]; i!=-1; i=edge[i].next)
{
int v=edge[i].v;
if(d[v]==-1)
{
d[v]=d[u]+1;
num[d[v]]++;
q.push(v);
}
}
}
}
int isap()
{
memcpy(cur,head,sizeof(cur));
int flow=0, u=pre[source]=source, i;
bfs();
while(d[source]<nv)
{
if(u==sink)
{
int f=INF, pos;
for(i=source; i!=sink; i=edge[cur[i]].v)
{
if(f>edge[cur[i]].cap)
{
f=edge[cur[i]].cap;
pos=i;
}
}
for(i=source; i!=sink; i=edge[cur[i]].v)
{
edge[cur[i]].cap-=f;
edge[cur[i]^1].cap+=f;
}
flow+=f;
u=pos;
}
for(i=cur[u]; i!=-1; i=edge[i].next)
{
if(d[edge[i].v]+1==d[u]&&edge[i].cap)
{
break;
}
}
if(i!=-1)
{
cur[u]=i;
pre[edge[i].v]=u;
u=edge[i].v;
}
else
{
if(--num[d[u]]==0) break;
int mind=nv;
for(i=head[u]; i!=-1; i=edge[i].next)
{
if(mind>d[edge[i].v]&&edge[i].cap)
{
mind=d[edge[i].v];
cur[u]=i;
}
}
d[u]=mind+1;
num[d[u]]++;
u=pre[u];
}
}
return flow;
}
int head1[2000], cnt1;
struct node1
{
int u, v, c, next;
}city[1000000];
void add1(int u, int v, int c)
{
city[cnt1].v=v;
city[cnt1].c=c;
city[cnt1].next=head1[u];
head1[u]=cnt1++;
}
int main()
{
int n, m, k, u, v, x, c, sum, i, j, kk;
while(scanf("%d%d",&n,&m)!=EOF&&(n+m))
{
memset(head,-1,sizeof(head));
memset(head1,-1,sizeof(head1));
cnt1=0;
cnt=0;
source=0;
sink=m+1;
nv=sink+1;
sum=0;
for(i=1;i<=m;i++)
{
scanf("%d",&val[i]);
}
scanf("%d",&k);
while(k--)
{
scanf("%d%d%d%d",&u,&v,&x,&c);
add1(u,v,x);
val[x]-=c;
}
for(i=1;i<=m;i++)
{
if(val[i]>0)
{
add(source,i,val[i]);
sum+=val[i];
}
else
add(i,sink,-val[i]);
}
for(i=1;i<=n;i++)
{
for(j=head1[i];j!=-1;j=city[j].next)
{
int v=city[j].v;
for(kk=head1[v];kk!=-1;kk=city[kk].next)
{
add(city[j].c,city[kk].c,INF);
}
}
}
int ans=sum-isap();
printf("%d\n",ans>0?ans:0);
}
return 0;
}
HDU 3917 Road constructions(最小割---最大权闭合)的更多相关文章
- hdu 3917 Road constructions 最大权闭合子图
样例说明: n(城市数目) m(工程队数目) 每个工程队上交的税收 val[i] k(k个工程) xi yi ci costi , 工程队ci承包由xi到yi,政府的补贴为costi 注意 ...
- 【POJ 2987】Firing (最小割-最大权闭合子图)
裁员 [问题描述] 在一个公司里,老板发现,手下的员工很多都不务正业,真正干事员工的没几个,于是老板决定大裁员,每开除一个人,同时要将其下属一并开除,如果该下属还有下属,照斩不误.给出每个人的贡献值和 ...
- 洛谷 - P1361 - 小M的作物 - 最小割 - 最大权闭合子图
第一次做最小割,不是很理解. https://www.luogu.org/problemnew/show/P1361 要把东西分进两类里,好像可以应用最小割的模板,其中一类A作为源点,另一类B作为汇点 ...
- [模拟赛FJOI Easy Round #2][T3 skill] (最小割+最大权闭合子图(文理分科模型))
[题目描述] 天上红绯在游戏中扮演敏剑,对于高攻击低防御的职业来说,爆发力显得非常重要,为此,她准备学习n个技能,每个技能都有2个学习方向:物理攻击和魔法攻击.对于第i个技能,如果选择物理攻击方向,会 ...
- BZOJ.1497.[NOI2006]最大获利(最小割 最大权闭合子图Dinic)
题目链接 //裸最大权闭合子图... #include<cstdio> #include<cctype> #include<algorithm> #define g ...
- Petya and Graph(最小割,最大权闭合子图)
Petya and Graph http://codeforces.com/contest/1082/problem/G time limit per test 2 seconds memory li ...
- 【BZOJ-3438】小M的作物 最小割 + 最大权闭合图
3438: 小M的作物 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 825 Solved: 368[Submit][Status][Discuss ...
- hdu 4289 Control(最小割 + 拆点)
http://acm.hdu.edu.cn/showproblem.php?pid=4289 Control Time Limit: 2000/1000 MS (Java/Others) Mem ...
- HDU 4859 海岸线(最小割+最大独立点权变形)
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题意: 欢迎来到珠海!由于土地资源越来越紧张,使得许多海滨城市都只能依靠填海来扩展市区以求发展.作为Z市的 ...
随机推荐
- MYECLIPSE中快速解决项目的错误的方法
Use the IDE's help as follows:- Right mouse click on the error in the 'Problems' view- Select the 'Q ...
- HTTP 协议基本知识
HTTP协议 7.1.什么是HTTP协议: HTTP协议是用来规定浏览器客户端和服务器通信的方式 7.2.基本原则 基于请求响应模型 一次请求对应一次响 ...
- WordPress 数据库操作WPDB对象($wpdb)用法详解【转载】
使用wordpress的时候,如果想直接使用WP里封装的数据库操作的类(wp-db.php),将wp-blog-header.php包含到代码中就可以使用了. define(‘PATH’, dirna ...
- 如何破解Webstorm 2016.2
嗯,随着Webstorm2016.2的推出,网上的很多破解方法已经不能用了,不过功夫不负有心人,我终于查到了新的方法, 选择“license server” 输入:http://114.215.133 ...
- vijos P1190繁忙的都市(Kruskal)(最小生成树)
P1190 繁忙的都市 城市C是一个非常繁忙的大都市,城市 中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉 ...
- RPD Volume 172 Issue 1-3 December 2016 评论02
Introduction to the special issue of Radiation Protection Dosimetry This special issue is a collecti ...
- 【费马小定理+快速幂+逆元】BZOJ3240-[NOI2013]矩阵游戏
[题目大意] 若用F[i][j]来表示矩阵中第i行第j列的元素,则F[i][j]满足下面的递推式:F[1][1]=1F[i,j]=a*F[i][j-1]+b (j!=1)①F[i,1]=c*F[i-1 ...
- c++基础类型之signed、unsigned的一个细节
数值型 c++中,对于 int.long.int64....等这些数值类型,如果是有符合的,则类型前加不加 signed 其效果都是一样的. 比如如下声明: int nA; // 与 signed i ...
- python的turtle模块画折线图
代码如下: import turtle yValues = [10.0,7.4,6.4,5.3,4.4,3.7,2.6] def main(): t = turtle.Turtle() t.hidet ...
- Oracle RAC 环境下的 v$log v$logfile
通常情况下,在Oracle RAC 环境中,v$视图可查询到你所连接实例的相关信息,而gv$视图则包含所有实例的信息.然而在RAC环境中,当我们查询v$log视图时说按照常理的话,v$log视图应当看 ...