题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3879

A famous mobile communication company is planning to build a new set of base stations. According to the previous investigation, n places are chosen as the possible new locations to build those new stations. However, the condition of each position varies much, so the costs to built a station at different places are different. The cost to build a new station at the ith place is Pi (1<=i<=n).

When complete building,
two places which both have stations can communicate with each
other.

Besides, according to the marketing department, the company has
received m requirements. The ith requirement is represented by three integers
Ai, Bi and Ci, which means if place Ai
and Bi can communicate with each other, the company will get
Ci profit.

Now, the company wants to maximize the profits, so
maybe just part of the possible locations will be chosen to build new stations.
The boss wants to know the maximum profits.

 
题意描述:有n个城市,在城市 i 建立新的驿站的花费为Pi,如果两个城市都有驿站则可以互相通信交流并且公司会因此获取到利益,比如A城市和B城市相互通信,那么可以获取到C的利益。问最大利益是多少。
算法分析:最大权闭合图。把两个城市相互通信的这条边看作点,比如A B C(如题意描述中解释),A和B的这条边看作点U,连边from到U,权值为C,连边U到A、U到B,权值为无穷大,连边A到to,B到to,权值为在此城市建立驿站的花费。
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#define inf 0x7fffffff
using namespace std;
const int maxn=+;
const int M = +; int n,m,from,to;
struct node
{
int v,flow;
int next;
}edge[M*];
int head[maxn],edgenum; void add(int u,int v,int flow)
{
edge[edgenum].v=v ;edge[edgenum].flow=flow;
edge[edgenum].next=head[u] ;head[u]=edgenum++ ; edge[edgenum].v=u ;edge[edgenum].flow=;
edge[edgenum].next=head[v] ;head[v]=edgenum++ ;
} int d[maxn];
int bfs()
{
memset(d,,sizeof(d));
d[from]=;
queue<int> Q;
Q.push(from);
while (!Q.empty())
{
int u=Q.front() ;Q.pop() ;
for (int i=head[u] ;i!=- ;i=edge[i].next)
{
int v=edge[i].v;
if (!d[v] && edge[i].flow)
{
d[v]=d[u]+;
Q.push(v);
if (v==to) return ;
}
}
}
return ;
} int dfs(int u,int flow)
{
if (u==to || flow==) return flow;
int cap=flow;
for (int i=head[u] ;i!=- ;i=edge[i].next)
{
int v=edge[i].v;
if (d[v]==d[u]+ && edge[i].flow)
{
int x=dfs(v,min(edge[i].flow,cap));
edge[i].flow -= x;
edge[i^].flow += x;
cap -= x;
if (cap==) return flow;
}
}
return flow-cap;
} int dinic()
{
int sum=;
while (bfs()) sum += dfs(from,inf);
return sum;
} int an[maxn];
int main()
{
while (scanf("%d%d",&n,&m)!=EOF)
{
memset(head,-,sizeof(head));
edgenum=;
from=n+m+;
to=from+;
for (int i= ;i<=n ;i++)
{
scanf("%d",&an[i]);
add(i,to,an[i]);
}
int a,b,c;
int sum=;
for (int i= ;i<=m ;i++)
{
scanf("%d%d%d",&a,&b,&c);
sum += c;
add(from,n+i,c);
add(n+i,a,inf);
add(n+i,b,inf);
}
printf("%d\n",sum-dinic());
}
return ;
}

hdu 3879 Base Station 最大权闭合图的更多相关文章

  1. HDU 3879 Base Station(最大权闭合子图)

    将第i个用户和他需要的基站连边,转化成求二分图的最大权闭合子图. 答案=正权点之和-最小割. # include <cstdio> # include <cstring> # ...

  2. hdu3879 Base Station 最大权闭合子图 边权有正有负

    /** 题目:hdu3879 Base Station 最大权闭合子图 边权有正有负 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3879 题意:给出n个 ...

  3. HDU 3879 Base Station(最大权闭合子图)

    经典例题,好像说可以转化成maxflow(n,n+m),暂时只可以勉强理解maxflow(n+m,n+m)的做法. 题意:输入n个点,m条边的无向图.点权为负,边权为正,点权为代价,边权为获益,输出最 ...

  4. HDU 3879 Base Station

    Base Station Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on HDU. Original I ...

  5. HDU 3879 && BZOJ 1497:Base Station && 最大获利 (最大权闭合图)

    http://acm.hdu.edu.cn/showproblem.php?pid=3879 http://www.lydsy.com/JudgeOnline/problem.php?id=1497 ...

  6. hdu 3879 hdu 3917 构造最大权闭合图 俩经典题

    hdu3879  base station : 各一个无向图,点的权是负的,边的权是正的.自己建一个子图,使得获利最大. 一看,就感觉按最大密度子图的构想:选了边那么连接的俩端点必需选,于是就以边做点 ...

  7. hdu 3879 最大权闭合图(裸题)

    /* 裸的最大权闭合图 解:参见胡波涛的<最小割模型在信息学竞赛中的应用 #include<stdio.h> #include<string.h> #include< ...

  8. hdu 3061 Battle 最大权闭合图

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3061 由于小白同学近期习武十分刻苦,很快被晋升为天策军的统帅.而他上任的第一天,就面对了一场极其困难的 ...

  9. hdu 3061 hdu 3996 最大权闭合图 最后一斩

    hdu 3061 Battle :一看就是明显的最大权闭合图了,水提......SB题也不说边数多少....因为开始时候数组开小了,WA....后来一气之下,开到100W,A了.. hdu3996. ...

随机推荐

  1. aspx页面中用Input 标签实现上传图片功能

    实现上传图片功能需单独的建立一个aspx页面, 其中前台页面需要注意两点: a)实现上传功能的input的type="file" b)设置请求报文头为 enctype=" ...

  2. MongoDB 插入文档

    文档的数据结构和JSON基本一样. 所有存储在集合中的数据都是BSON格式. BSON是一种类json的一种二进制形式的存储格式,简称Binary JSON. 插入文档 MongoDB 使用 inse ...

  3. Cassandra 技术选型的问题

    Cassandra在国内资料少,用的也不多,大家更多抱观望态度吧. 为了扩大Cassandra队伍帮助自己采坑,决定写一篇文章,就自己对Cassandra的理解范围进行介绍. 选用Cassandra的 ...

  4. C++列出完数

    题目内容:自然数中,完数寥若晨星,请在从1到某个整数范围中打印出所有的完数来.所谓“完数”是指一个数恰好等于它的所有不同因子之和.例如,6是完数,因为6=1+2+3.而24不是完数,因为24≠1+2+ ...

  5. php 判断table 是否存在 根据返回值继续下一步的操作

    根据sql命令创建数据库或者数据表时候,判断库或者表是否存在比较重要. //要创建的表是否已经存在 function isHaveTable( $dbName,$tableN, $con)  //数据 ...

  6. USB总线介绍

    •USB 1.0出现在1996年的,速度只有1.5Mb/s1998年升级为USB 1.1,速度也提升到12Mb/s,称之为”full speed” •USB2.0规范是由USB1.1规范演变而来的.它 ...

  7. GRE协议学习与练习

    通用路由封装(英语:Generic Routing Encapsulation,缩写为GRE),一种隧道协议,可以在虚拟点对点链路中封装多种网络层协议.由思科系统开发 以下是GRE协议的简单练习 网络 ...

  8. html/css 盒子布局 Margin 、Padding 、border 以及 清除浮动的知识 (学习HTML过程中的小记录)

    html/css  盒子布局 Margin .Padding .border 以及 清除浮动的知识 (学习HTML过程中的小记录) 作者:王可利(Star·星星) width     是"宽 ...

  9. eclipse java 空心J文件的回复

    eclipse中的空心J的java文件,表示当前文件不包含在项目中进行编译,而仅仅是当做资源存在项目中. 解决方案如下: 1.鼠标右击当前空心j文件,-->build path-->inc ...

  10. VS2010遇到_WIN32_WINNT宏定义问题

    最近拿到一个别人的工程,是使用VS.net创建的,而我的机器上只有vs2010,于是用自带的转换工具将它转换成vs2010的工程,转换之前我就很担心,怕转换完后会出问题,但是没有办法,我实在是不想再安 ...