Destroying The Graph
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 8503   Accepted: 2753   Special Judge

Description

Alice and Bob play the following game. First, Alice draws some directed graph with N vertices and M arcs. After that Bob tries to destroy it. In a move he may take any vertex of the graph and remove either all arcs incoming into this vertex, or all arcs outgoing from this vertex.
Alice assigns two costs to each vertex: Wi+ and Wi-. If Bob removes all arcs incoming into the i-th vertex he pays Wi+ dollars to Alice, and if he removes outgoing arcs he pays Wi- dollars.
Find out what minimal sum Bob needs to remove all arcs from the graph.

Input

Input file describes the graph Alice has drawn. The first line of the input file contains N and M (1 <= N <= 100, 1 <= M <= 5000). The second line contains N integer numbers specifying Wi+. The third line defines Wi- in a similar way. All costs are positive and do not exceed 106 . Each of the following M lines contains two integers describing the corresponding arc of the graph. Graph may contain loops and parallel arcs.

Output

On the first line of the output file print W --- the minimal sum Bob must have to remove all arcs from the graph. On the second line print K --- the number of moves Bob needs to do it. After that print K lines that describe Bob's moves. Each line must first contain the number of the vertex and then '+' or '-' character, separated by one space. Character '+' means that Bob removes all arcs incoming into the specified vertex and '-' that Bob removes all arcs outgoing from the specified vertex.

Sample Input

3 6
1 2 3
4 2 1
1 2
1 1
3 2
1 2
3 1
2 3

Sample Output

5
3
1 +
2 -
2 + 主要是找割边。
有构造出来的图知道这个是个二部图加两个源点汇点,二部图之间的连边不可能是割边(INF),所以就dfs(S)然后用vis标记,那么vis[S]一定是1,并且vis[T]一定是0.因为S,T不可能在一个集合里
那么从源点处找一下和它相连的边,看vis[]是不是0,是的话就是割边。
然后从汇点处找一下和它相连的边,看vis[]是不是1,是的话就是割边。
因为是个二部图所以不用dfs直接找一次就可以了
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
const int M=;
const int INF=1e9+;
int head[N],tot,S,T;
int q[N],dis[N],n,m,Q;
bool vis[N];
struct node
{
int next,v,w;
} e[M<<];
void add(int u,int v,int w)
{
e[tot].v=v;
e[tot].w=w;
e[tot].next=head[u];
head[u]=tot++;
}
bool bfs()
{
memset(dis,-,sizeof(dis));
dis[S]=;
int l=,r=;
q[r++]=S;
while(l<r)
{
int u=q[l++];
for(int i=head[u]; ~i; i=e[i].next)
{
int v=e[i].v;
if(dis[v]==-&&e[i].w>)
{
q[r++]=v;
dis[v]=dis[u]+;
if(v==T) return true;
}
}
}
return false;
}
int dfs(int s,int low)
{
if(s==T||!low) return low;
int ans=low,a;
for(int i=head[s]; ~i; i=e[i].next)
{
if(e[i].w>&&dis[e[i].v]==dis[s]+&&(a=dfs(e[i].v,min(e[i].w,ans))))
{
e[i].w-=a;
e[i^].w+=a;
ans-=a;
if(!ans) return low;
}
}
if(low==ans) dis[s]=-;
return low-ans;
}
void dfs(int u){
vis[u]=;
for(int i=head[u];~i;i=e[i].next) if(!vis[e[i].v]&&e[i].w) dfs(e[i].v);
}
int a[N],b[N];
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
S=,T=*n+;
int x,f,t;
memset(head,-,sizeof(head));
tot=;
for(int i=; i<=n; ++i)
{
scanf("%d",&x);
add(S,i,x);
add(i,S,);
}
for(int i=; i<=n; ++i)
{
scanf("%d",&x);
add(i+n,T,x);
add(T,i+n,);
}
while(m--)
{
scanf("%d%d",&f,&t);
add(t,f+n,INF);
add(f+n,t,);
}
int ans=;
while(bfs()) ans+=dfs(S,INF);
printf("%d\n",ans);
dfs(S);
int ct1=,ct2=;
for(int i=head[S];~i;i=e[i].next) if(!vis[e[i].v]) a[ct1++]=e[i].v;
for(int i=head[T];~i;i=e[i].next) if(vis[e[i].v]) b[ct2++]=e[i].v-n;
printf("%d\n",ct1+ct2);
for(int i=;i<ct1;++i) printf("%d +\n",a[i]);
for(int i=;i<ct2;++i) printf("%d -\n",b[i]); }
}

poj2125最小点权覆盖+找一个割集的更多相关文章

  1. poj2125 最小点权覆盖集

    题意:有一张图,对于每个点,有出边和入边,现在目的是删除改图的所有边,对于每个点,删除出边的花费Wi-,删除入边的花费Wi+,现在的目的求删去所有边后的花费最小. 建图方法:对于每个点i,拆点为i,i ...

  2. POJ2125 Destroying The Graph(二分图最小点权覆盖集)

    最小点权覆盖就是,对于有点权的有向图,选出权值和最少的点的集合覆盖所有的边. 解二分图最小点权覆盖集可以用最小割: vs-X-Y-vt这样连边,vs和X部点的连边容量为X部点的权值,Y部和vt连边容量 ...

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

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

  4. POJ2125 Destroying The Graph 二分图 + 最小点权覆盖 + 最小割

    思路来源:http://blog.csdn.net/lenleaves/article/details/7873441 求最小点权覆盖,同样求一个最小割,但是要求出割去了那些边, 只要用最终的剩余网络 ...

  5. POJ 2125 Destroying The Graph 二分图 最小点权覆盖

    POJ2125 题意简述:给定一个有向图,要通过某些操作删除所有的边,每一次操作可以选择任意一个节点删除由其出发的所有边或者通向它的所有边,两个方向有不同的权值.问最小权值和的解决方案,要输出操作. ...

  6. [学习笔记]最小割之最小点权覆盖&&最大点权独立集

    最小点权覆盖 给出一个二分图,每个点有一个非负点权 要求选出一些点构成一个覆盖,问点权最小是多少 建模: S到左部点,容量为点权 右部点到T,容量为点权 左部点到右部点的边,容量inf 求最小割即可. ...

  7. POJ 2125 最小点权覆盖集(输出方案)

    题意:给一个图(有自回路,重边),要去掉所有边,规则:对某个点,可以有2种操作:去掉进入该点 的所有边,也可以去掉出该点所有边,(第一种代价为w+,第二种代价为w-).求最小代价去除所有边. 己思:点 ...

  8. POJ 2125 Destroying The Graph (二分图最小点权覆盖集+输出最小割方案)

    题意 有一个图, 两种操作,一种是删除某点的所有出边,一种是删除某点的所有入边,各个点的不同操作分别有一个花费,现在我们想把这个图的边都删除掉,需要的最小花费是多少. 思路 很明显的二分图最小点权覆盖 ...

  9. POJ 3308 Paratroopers (对数转换+最小点权覆盖)

    题意 敌人侵略r*c的地图.为了消灭敌人,可以在某一行或者某一列安置超级大炮.每一个大炮可以瞬间消灭这一行(或者列)的敌人.安装消灭第i行的大炮消费是ri.安装消灭第j行的大炮消费是ci现在有n个敌人 ...

随机推荐

  1. 徐州A

    #include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<=b;++i) #defi ...

  2. Vue中的父子传值问题

    个人网站 https://iiter.cn 程序员导航站 开业啦,欢迎各位观众姥爷赏脸参观,如有意见或建议希望能够不吝赐教! 好久没更博了,感觉下班后的时间莫名其妙就没有了,有了,了... 趁着端午放 ...

  3. 从零开始制作数据集所需要的所有python脚本

    最近一直在做图片数据集,积累了很多心得.我把我所使用的python脚本全部拿出来,当然这些脚本大部分网上都有,只不过比较分散. 我已经把所有代码上传到github上,觉得写的好的话,请给我一个star ...

  4. <学习笔记: Django之初见>

    Django 1. web框架介绍 具体介绍Django之前,必须先介绍WEB框架等概念. web框架: 别人已经设定好的一个web网站模板,你学习它的规则,然后“填空”或“修改”成你自己需要的样子. ...

  5. turtle库应用实例3-叠加等边三角形绘制(一笔画)

    叠加等边三角形绘制 ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬ ...

  6. Web 组态运用之用户数据 ARPU 分析图

    前言 作为企业的发展,通过运营的有效管理,增加收入.降低成本,取得更好的经济效益,是核心所在,在电信企业同样如此.电信企业的利润大体上是由业务收入和成本决定的,而收入和成本又可进一步分别分解表达为不同 ...

  7. 05_CSS入门和高级技巧(3)

    上节课复习 !important不能影响就近原则,远的标签如果加上!important也干不过近的标签! !important不能影响继承权重是0,通过继承的标签加上!important也干不过直接选 ...

  8. 【Scala】用实例弄清楚scala几种函数的定义和特点

    文章目录 作为参数的函数 匿名函数 柯里化函数(currying) 闭包函数 作为参数的函数 scala> val a1 = Array(1,2,3,4) //这是一个数组 a1: Array[ ...

  9. C# 数据操作系列 - 2. ADO.NET操作

    0.前言 在上一篇中初略的介绍了一下SQL的基本写法,这一篇开始我们正式步入C#操作数据库的范围.通过这一系列的内容,我想大家能对于数据库交互有了一定的认识和基础.闲话不多说,先给大家介绍一个C#操作 ...

  10. Vulnhb 靶场系列:Jarbas1.0

    靶场镜像 官网 信息收集 攻击机kali IP地址 通过nmap 进行主机发现,发现目标机IP地址 nmap -sP 192.168.227.1/24 参数说明: -sP (Ping扫描) 该选项告诉 ...