题目链接:ヾ(≧∇≦*)ゝ

大致题意:

给出一个有向图D=(V,E).对于每个点U,定义两种操作a(u),b(u)

操作a(u):删除点U的所有出边,即属于E,操作花费为Ca(u).

操作b(u):删除点U的所有入边,即属于E,操作花费为Cb(u).

求将原图的边集的边全部删除的最小代价,总操作数和具体操作

Solution:

第一问很简单,首先,对于每一个点,把它分成出点和入点。

把每个点的出点与S相连,入点与T相连。边容量分别为删除该点所有入边和出边的花费。

然后对于每条边 a -> b,就把a的出点与b的入点连一条容量为inf的边。

根据最大流=最小割,跑一遍dinic就能得到答案了。

对于第二、三问,我们分别统计a操作和b操作。

我们先对剩余网络进行bfs(),把能够扫到的点都标记为1,不能的标记为0。

对于一个点u,如果要使用a(u),那么显然,需要至少存在一个点v,满足u -> v &&

vis[u]vis[v]0。

而对于点u,如果要使用b(u),只需要满足vis[u]==1就行了。

为了防止重复输出,在定义一个apr数组记录每个数是否加入到答案中就行了。

详见代码

Code:

  1. #include<queue>
  2. #include<ctype.h>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<algorithm>
  6. #define N 1001
  7. #define M 20001
  8. #define inf 1926081700
  9. using namespace std;
  10. int S,T,head[N];
  11. int n,m,cnt=1;
  12. int ru[N],cu[N];
  13. int ans,vis[N],apr[N];
  14. int t1,t2,fst[N],sec[N];
  15. struct Edge{int nxt,to,val;}edge[M];
  16. void ins(int x,int y,int z){
  17. edge[++cnt].nxt=head[x];
  18. edge[cnt].to=y;edge[cnt].val=z;
  19. head[x]=cnt;
  20. }
  21. namespace Network_Flow{
  22. queue<int> q;
  23. int dep[N];
  24. int bfs(){
  25. memset(dep,0,sizeof(dep));
  26. q.push(S);dep[S]=1;
  27. while(!q.empty()){
  28. int x=q.front();q.pop();
  29. for(int i=head[x];i;i=edge[i].nxt){
  30. int y=edge[i].to,v=edge[i].val;
  31. if(!dep[y]&&v){
  32. q.push(y);
  33. dep[y]=dep[x]+1;
  34. }
  35. }
  36. }
  37. return dep[T];
  38. }
  39. int dfs(int x,int rest){
  40. if(x==T||rest<=0) return rest;
  41. int flow=0;
  42. for(int i=head[x];i;i=edge[i].nxt){
  43. int y=edge[i].to,v=edge[i].val;
  44. if(dep[y]==dep[x]+1&&v){
  45. int now=dfs(y,min(rest,v));
  46. edge[i].val-=now;
  47. edge[i^1].val+=now;
  48. flow+=now;rest-=now;
  49. if(!rest) break;
  50. }
  51. }
  52. return flow;
  53. }
  54. int dinic(){
  55. int maxflow=0;
  56. while(bfs()) maxflow+=dfs(S,inf);
  57. return maxflow;
  58. }
  59. }
  60. void getspj(){
  61. queue<int> s;
  62. s.push(S);vis[S]=1;
  63. while(!s.empty()){
  64. int x=s.front();s.pop();
  65. for(int i=head[x];i;i=edge[i].nxt)
  66. if(!vis[edge[i].to]&&edge[i].val){
  67. s.push(edge[i].to);
  68. vis[edge[i].to]=1;
  69. }
  70. }
  71. apr[S]=apr[T]=1;
  72. }
  73. int read(){
  74. int x=0,f=1;char ch=getchar();
  75. while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
  76. while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
  77. return x*f;
  78. }
  79. int main(){
  80. n=read(),m=read();
  81. S=n*2+1,T=S+1;
  82. for(int i=1;i<=n;i++) ru[i]=read();
  83. for(int i=1;i<=n;i++) cu[i]=read();
  84. for(int i=1;i<=n;i++){
  85. ins(S,i,cu[i]);ins(i,S,0);
  86. ins(i+n,T,ru[i]);ins(T,i+n,0);
  87. }
  88. for(int x,y,i=1;i<=m;i++){
  89. x=read(),y=read();
  90. ins(x,n+y,inf);
  91. ins(n+y,x,0);
  92. }
  93. using namespace Network_Flow;
  94. printf("%d\n",dinic());getspj();
  95. for(int i=1;i<=n;i++)
  96. for(int j=head[i];j;j=edge[j].nxt){
  97. int y=edge[j].to;
  98. if(!vis[i]&&!vis[y]&&!apr[i]){
  99. sec[++t2]=i;
  100. ans++;apr[i]=1;
  101. }
  102. if(!apr[y]&&vis[y]){
  103. fst[++t1]=y%n;
  104. if(!fst[t1]) fst[t1]=n;
  105. ans++;apr[y]=1;
  106. }
  107. }
  108. printf("%d\n",ans);
  109. for(int i=1;i<=t1;i++) printf("%d +\n",fst[i]);
  110. for(int i=1;i<=t2;i++) printf("%d -\n",sec[i]);
  111. return 0;
  112. }

POJ2125 Destroying The Graph的更多相关文章

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

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

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

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

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

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

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

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

  5. 【POJ】【2125】Destroying the Graph

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

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

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

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

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

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

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

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

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

随机推荐

  1. 微信小程序开发 [05] wx.request发送请求和妹纸图

    1.wx.request 微信小程序中用于发起网络请求的API就是wx.request了,具体的参数太多,此处就不再一一详举了,基本使用示例如下: wx.request({ url: 'test.ph ...

  2. python_环境的配置

    1.首先登入官网:https://www.python.org/downloads/windows/ 下载: 下载executable installer 2.安装 ipython,jupyter 地 ...

  3. mysql事务,select for update,及数据的一致性处理

    在MySQL的InnoDB中,预设的Tansaction isolation level 为REPEATABLE READ(可重读) 在SELECT 的读取锁定主要分为两种方式: SELECT ... ...

  4. 20155227《网络对抗》Exp9 Web安全基础实践

    20155227<网络对抗>Exp9 Web安全基础实践 实验内容 关于WebGoat Cross-Site Scripting(XSS)练习 Injection Flaws练习 CSRF ...

  5. 20155238 Java第13周课堂实践

    类定义 实验内容及要求 设计并实现一个Book类,定义义成Book.java,Book 包含书名,作者,出版社和出版日期,这些数据都要定义getter和setter.定义至少三个构造方法,接收并初始化 ...

  6. 20155331《网络对抗技术》Exp4:恶意代码分析

    20155331<网络对抗技术>Exp4:恶意代码分析 实验过程 计划任务监控 在C盘根目录下建立一个netstatlog.bat文件(先把后缀设为txt,保存好内容后记得把后缀改为bat ...

  7. Egret(白鹭引擎)——“TypeError: Cannot read property 'asCom' of null”

    前言 相信我,这个错误新手都不陌生:TypeError: Cannot read property 'asCom' of null 还有,一定要看我上一篇,哦不(人家应该是报了这个错,才找到看到这篇文 ...

  8. webVR全景图多种方案实现(pannellum,aframe,Krpano,three,jquery-vrview)

    前言 有一篇文章我说了H5实现全景图预览,全景视频播放的原理,有需要的小伙伴可以自行去看一下 今天我就拿出我的实践干货出来,本人实测实测过 需求 老板:我需要可以上传全景图片,然后手机网站上都可以36 ...

  9. 你应该知道Go语言的几个优势

    要说起GO语言的优势,我们就得从GO语言的历史讲起了-- 本文由腾讯技术工程官方号发表在腾讯云+社区 2007年,受够了C++煎熬的Google首席软件工程师Rob Pike纠集Robert Grie ...

  10. python 连接 hive 的 HiveServer2 的配置坑

    环境: hadoop 2.7.6 hive 2.3.4 Hive 的 thirft 启动: hadoop 单机或者集群需要: 启动 webhdfs 修改 hadoop 的代理用户 <proper ...