HDU 3879 Base Station(最大权闭合子图)
将第i个用户和他需要的基站连边,转化成求二分图的最大权闭合子图。
答案=正权点之和-最小割。
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi 3.1415926535
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int res=, flag=;
char ch;
if((ch=getchar())=='-') flag=;
else if(ch>=''&&ch<='') res=ch-'';
while((ch=getchar())>=''&&ch<='') res=res*+(ch-'');
return flag?-res:res;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... struct Edge{int p, next, w;}edge[];
int head[N], cnt=, s, t, vis[N];
queue<int>Q; void add_edge(int u, int v, int w){
edge[cnt].p=v; edge[cnt].w=w; edge[cnt].next=head[u]; head[u]=cnt++;
edge[cnt].p=u; edge[cnt].w=; edge[cnt].next=head[v]; head[v]=cnt++;
}
int bfs(){
int i, v;
mem(vis,-);
vis[s]=; Q.push(s);
while (!Q.empty()) {
v=Q.front(); Q.pop();
for (i=head[v]; i; i=edge[i].next) {
if (edge[i].w> && vis[edge[i].p]==-) {
vis[edge[i].p]=vis[v] + ;
Q.push(edge[i].p);
}
}
}
return vis[t]!=-;
}
int dfs(int x, int low){
int i, a, temp=low;
if (x==t) return low;
for (i=head[x]; i; i=edge[i].next) {
if (edge[i].w> && vis[edge[i].p]==vis[x]+){
a=dfs(edge[i].p,min(edge[i].w,temp));
temp-=a; edge[i].w-=a; edge[i^].w += a;
if (temp==) break;
}
}
if (temp==low) vis[x]=-;
return low-temp;
}
int main ()
{
int n, m, u, v, tmp;
while (~scanf("%d%d",&n,&m)) {
s=, t=n+m+;
int res=, sum=;
mem(head,); cnt=;
FOR(i,,n) scanf("%d",&tmp), add_edge(m+i,t,tmp);
FOR(i,,m) {
scanf("%d%d%d",&u,&v,&tmp); res+=tmp;
add_edge(s,i,tmp); add_edge(i,m+u,INF); add_edge(i,m+v,INF);
}
while (bfs()) while (tmp=dfs(s,INF)) sum+=tmp;
printf("%d\n",res-sum);
}
return ;
}
HDU 3879 Base Station(最大权闭合子图)的更多相关文章
- hdu 3879 Base Station 最大权闭合图
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3879 A famous mobile communication company is plannin ...
- hdu3879 Base Station 最大权闭合子图 边权有正有负
/** 题目:hdu3879 Base Station 最大权闭合子图 边权有正有负 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3879 题意:给出n个 ...
- HDU 3879 Base Station(最大权闭合子图)
经典例题,好像说可以转化成maxflow(n,n+m),暂时只可以勉强理解maxflow(n+m,n+m)的做法. 题意:输入n个点,m条边的无向图.点权为负,边权为正,点权为代价,边权为获益,输出最 ...
- HDU 3879 Base Station
Base Station Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on HDU. Original I ...
- hdu 5772 String problem 最大权闭合子图
String problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5772 Description This is a simple pro ...
- hdu 3917 Road constructions 最大权闭合子图
样例说明: n(城市数目) m(工程队数目) 每个工程队上交的税收 val[i] k(k个工程) xi yi ci costi , 工程队ci承包由xi到yi,政府的补贴为costi 注意 ...
- HDU 5855 Less Time, More profit 最大权闭合子图
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5855 Less Time, More profit Time Limit: 2000/1000 MS ...
- HDU4971 A simple brute force problem.(强连通分量缩点 + 最大权闭合子图)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=4971 Description There's a company with several ...
- HDU5855 Less Time, More profit(最大权闭合子图)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5855 Description The city planners plan to build ...
随机推荐
- 聊天功能插件Socket.io
一.Socket.io是什么 是基于时间的实时双向通讯库 基于websocket协议的 前后端通过时间进行双向通讯 配合express快速开发实时应用 二.Socket.io和ajax区别 基于不同的 ...
- Java基础——语法基础
一.标识符 1.不能使用数字开头 2.不能使用关键字 (更多命名规范,参见基础加强随笔) 二.数据类型 主要分为四种: 整形: byte 1字节8位 范围 -128~127 short 2 ...
- c++中string (MFC)
题目:UVALive - 6439 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid= ...
- 北京Uber优步司机奖励政策(3月9日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- zedboard学习第一篇
1. 刚开始学习使用,不知道从哪里开始,手上的资料也很乱,至于这个板子需要学什么也不清楚. 2. 第一个工程就从helloworld开始吧,Zed板上的Zynq是一个PS(processing sys ...
- Richardson成熟度模型
Richardson Maturity Model(RMM) 迈向REST的辉煌 一个模型(由Leonard Richardson开发)将REST方法的主要元素分解为三个步骤.这些引入资源,http动 ...
- OSG-阴影
本文转至http://www.cnblogs.com/shapherd/archive/2010/08/10/osg.html 作者写的比较好,再次收藏,希望更多的人可以看到这个文章 互联网是是一个相 ...
- 阿里云ECS下CentOS7.4 yum安装Python3.6环境
一.安装EPEL和IUS软件源 二.安装Python3.6 三.创建python3软链接连接符 四.安装pip3 五.创建pip3链接符 六.进行验证是否安装成功 一.安装EPEL和IUS软件源 yu ...
- 博客美化—添加萌萌的live2D看板娘(不能再简单了)
看着很多博客都有live2D的萌萌哒看板娘,我闲着有空说干就干. 从参考博客的附件中下载资源文件 waifu.css waifu-tips.js live2d.js flat-ui.min.css// ...
- javascript对table的添加,删除行的操作
<body> <form name="myForm"> <table width="100%" id="tab" ...