题目大意:
有一张有向图,对于每个点,有两种操作:
1. 删掉它的所有入边
2. 删掉它的所有出边
对每个点的每个操作均有不同的价值。
求使得图上没有边的最小价值。
解题思路:
考虑把点拆成入点和出点,然后就是二分图最小点权覆盖集。
也可以考虑最小割。
从S到每个点的入点连容量为该点执行操作2的价值,每个点的出点到T连容量为该点执行操作1的价值。对于图上的每条边连容量inf的边。
然后答案就是最小割(割一条S出发的边,相当于执行了2操作,网络流不可能从该点再流向其他节点,则相当于删掉出边。操作1同理)。

C++ Code:

#include<bits/stdc++.h>
using namespace std;
const int S=0,T=10005,inf=0x3fffffff;
struct edge{
int to,nxt,cap;
}e[200005];
int head[10050],cnt=1,n,m,level[10050],iter[10050];
inline void addedge(int from,int to,int flow){
e[++cnt]=(edge){to,head[from],flow};
head[from]=cnt;
e[++cnt]=(edge){from,head[to],0};
head[to]=cnt;
}
queue<int>q;
void bfs(){
level[S]=1;
for(q.push(S);!q.empty();){
int u=q.front();
q.pop();
for(int i=head[u];~i;i=e[i].nxt)
if(e[i].cap&&!~level[e[i].to]){
level[e[i].to]=level[u]+1;
q.push(e[i].to);
}
}
}
inline int min(int a,int b){return a<b?a:b;}
int dfs(int u,int f){
if(!f||u==T)return f;
for(int& i=iter[u];~i;i=e[i].nxt)
if(e[i].cap&&level[e[i].to]>level[u]){
int d=dfs(e[i].to,min(f,e[i].cap));
if(d){
e[i].cap-=d;
e[i^1].cap+=d;
return d;
}else level[e[i].to]=-1;
}
return 0;
}
int dinic(){
for(int flow=0,f;;){
memset(level,-1,sizeof iter);
if(bfs(),!~level[T])return flow;
memcpy(iter,head,sizeof iter);
while(f=dfs(S,inf))flow+=f;
}
}
int main(){
memset(head,-1,sizeof head);
ios::sync_with_stdio(false);cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;++i){
int p;
cin>>p;
addedge(i+n,T,p);
}
for(int i=1;i<=n;++i){
int p;
cin>>p;
addedge(S,i,p);
}
while(m--){
int x,y;
cin>>x>>y;
addedge(x,y+n,inf);
}
cout<<dinic()<<endl;
return 0;
}

[BZOJ1322]Destroying The Graph的更多相关文章

  1. POJ 2125 Destroying the Graph 二分图最小点权覆盖

    Destroying The Graph Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8198   Accepted: 2 ...

  2. POJ2125 Destroying The Graph (最小点权覆盖集)(网络流最小割)

                                                          Destroying The Graph Time Limit: 2000MS   Memo ...

  3. 【POJ】【2125】Destroying the Graph

    网络流/二分图最小点权覆盖 果然还是应该先看下胡伯涛的论文…… orz proverbs 题意: N个点M条边的有向图,给出如下两种操作.删除点i的所有出边,代价是Ai.删除点j的所有入边,代价是Bj ...

  4. 图论(网络流,二分图最小点权覆盖):POJ 2125 Destroying The Graph

    Destroying The Graph   Description Alice and Bob play the following game. First, Alice draws some di ...

  5. POJ 2125 Destroying The Graph [最小割 打印方案]

    Destroying The Graph Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8311   Accepted: 2 ...

  6. poj 2125 Destroying The Graph (最小点权覆盖)

    Destroying The Graph http://poj.org/problem?id=2125 Time Limit: 2000MS   Memory Limit: 65536K       ...

  7. AC日记——Destroying The Graph poj 2125

    Destroying The Graph Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8356   Accepted: 2 ...

  8. Destroying The Graph 最小点权集--最小割--最大流

    Destroying The Graph 构图思路: 1.将所有顶点v拆成两个点, v1,v2 2.源点S与v1连边,容量为 W- 3.v2与汇点连边,容量为 W+ 4.对图中原边( a, b ), ...

  9. Destroying The Graph(poj 2125)

    题意: 给你一张有向图,你可以选择一个点:• 摧毁其所有的入边,代价A[i].• 摧毁其所有的出边,代价B[i].• 求摧毁这张图的最小代价.• 数据范围1000 /* 很经典的一道题目(我这么弱,稍 ...

随机推荐

  1. 为什么在JavaScript中0.1+0.2不等于0.3?

    0.1+0.2不等于0.3?是不是有点颠覆你的认知,但是,在js中,是真实存在的! console.log(0.1+0.2); // 0.30000000000000004 其实这都是因为浮点数运算的 ...

  2. nyoj256-C小加之级数求和

    C小加 之 级数求和 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 最近,C小加 又遇到难题了,正寻求你的帮助. 已知:Sn= 1+1/2+1/3+-+1/n. 显然对 ...

  3. [bzoj3505 Cqoi2014] 数三角形 (容斥+数学)

    传送门 Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形. 注意三角形的三点不能共线. Input 输入一行,包含两个空格分隔的正 ...

  4. Ansible常见问题处理

    1.ansible all -m ping报错,信息如下: [WARNING]: log file at /var/log/ansible.log is not writeable and we ca ...

  5. android window类

    Android的Window类(一) Android的GUI层并不复杂.它的复杂度类似于WGUI这类基于布局和对话框的GUI,与MFC.QT等大型框架没有可比性,甚至飞漫魏永明的MiniGUI都比它复 ...

  6. 使用c++Beep实现春节十二响蜂鸣程序

    直接编译运行即可 #include<bits/stdc++.h> #include<windows.h> using namespace std; char a[31][71] ...

  7. phpEXCEL如何设置单元格格式为百分比

    $objExcel->getActiveSheet()->getStyle('C9')->getNumberFormat()->setFormatCode(PHPExcel_S ...

  8. 《Javascript权威指南》学习笔记之十五:BOM之源---window对象

    BOM是Browser Object Model的缩写,即浏览器对象模型,提供了独立于网页内容和浏览器窗体之间进行交互的APi.API由若干对象组成,因为浏览器是Javascript的宿主,因此,这些 ...

  9. centos编译ffmpeg x264

    1.安装汇编编译器(一般系统自带吧).假设没有依照以下的命令安装吧 yum install yasm 2.使用最新x264源代码编译(仅仅支持编码)    在x264官网下载最新的代码http://w ...

  10. CF 558C(Amr and Chemistry-构造法)

    C. Amr and Chemistry time limit per test 1 second memory limit per test 256 megabytes input standard ...