题目大意:
有一张有向图,对于每个点,有两种操作:
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. Project Euler 20 Factorial digit sum( 大数乘法 )

    题意:求出100!的各位数字和. /************************************************************************* > Fil ...

  2. [SDOI2016]数字配对(费用流+贪心+trick)

    重点是如何找到可以配对的\(a[i]\)和\(a[j]\). 把\(a[i]\)分解质因数.设\(a[i]\)分解出的质因数的数量为\(cnt[i]\). 设\(a[i]\geq a[j]\) 那么\ ...

  3. 园区IP地址规划(非常详细)

    转:https://mp.weixin.qq.com/s/Zlm7x5eunIYLAG7Sp0yVCQ 经过这些年工作,接触从几万.几十万到上亿的项目都有: 我简单总结了接触的大部分的项目,将园区网核 ...

  4. JavaScript链式编程模拟Jquery函数

    <span>Hello,World!</span> <script type="text/javascript"> Jq = function ...

  5. 利用Tensorflow实现手写字符识别

    模式识别领域应用机器学习的场景非常多,手写识别就是其中一种,最简单的数字识别是一个多类分类问题,我们借这个多类分类问题来介绍一下google最新开源的tensorflow框架,后面深度学习的内容都会基 ...

  6. Jquery学习总结(5)——jQuery选择器

    1. #id : 根据给定的ID匹配一个元素 <p id="myId">这是第一个p标签</p> <p id="not">这 ...

  7. Redis-Cluster集群原理

    一.redis-cluster 官方推荐的 redis 集群解决方案,优点在于去中心化, 去中间件,也就是说,集群中的每个节点都是平等的关系,都是对等的,每个节点都保存各自的数据和整个集群的状态.每个 ...

  8. 设置编码格式为utf8

    response.setCharacterEncoding("UTF-8"); 在Servlet2.3中是不行的,至少要2.4版本才可以,如果低于2.4版本,可以用如下办法: re ...

  9. A server is already running. Check tmp/pids/server.pid.

    A server is already running. Check  tmp/pids/server.pid. 把server.pid删除: 学习了: http://stackoverflow.co ...

  10. c6----函数的声明和实现

    // // main.c // 函数的声明和定义 // // Created by xiaomage on 15/6/7. // Copyright (c) 2015年 xiaomage. All r ...