Pollutant Control
Hal Burch

It's your first day in Quality Control at Merry Milk Makers, and already there's been a catastrophe: a shipment of bad milk has been sent out. Unfortunately, you didn't discover this until the milk was already into your delivery system on its way to stores. You know which grocer that milk was destined for, but there may be multiple ways for the milk to get to that store.

The delivery system is made up of a several warehouses, with trucks running from warehouse to warehouse moving milk. While the milk will be found quickly, it is important that it does not make it to the grocer, so you must shut down enough trucks to ensure that it is impossible for the milk to get to the grocer in question. Every route costs a certain amount to shut down. Find the minimum amount that must be spent to ensure the milk does not reach its destination, along with a set of trucks to shut down that achieves this goal at that cost.

PROGRAM NAME: milk6

INPUT FORMAT

Line 1: Two space separated integers, N and M. N (2 <= N <= 32) is the number of warehouses that Merry Milk Makers has, and M (0 <= M <= 1000) is the number of trucks routes run. Warehouse 1 is actually the productional facility, while warehouse N is the grocer to which which the bad milk was destined.
Line 2..M+1: Truck routes: three space-separated integers, Si, Ei, and Ci. Si and Ei (1 <= Si,Ei <= N) correspond to the pickup warehouse and dropoff warehouse for the truck route. Ci (0 <= Ci <= 2,000,000) is the cost of shutting down the truck route.

SAMPLE INPUT (file milk6.in)

4 5
1 3 100
3 2 50
2 4 60
1 2 40
2 3 80

OUTPUT FORMAT

The first line of the output should be two integers, C and T. C is the minimum amount which must be spent in order to ensure the our milk never reaches its destination. T is the minimum number of truck routes that you plan to shut down in order to achive this goal. The next T lines sould contain a sorted list of the indexes of the truck routes that you suggest shutting down. If there are multiple sets of truck routes that achieve the goal at minimum cost, choose one that shuts down the minimum number of routes. If there are still multiple sets, choose the one whose initial routes have the smallest index.

SAMPLE OUTPUT (file milk6.out)

60 1
3

———————————————————————————————————————题解第一次写最小割解集,总结一下【1】最小割在数值上等于最大流【2】在残余网络中求与源点s相连的点集S,其余的点是T【3】最小割的割集就是一个点在S一个点在T中的弧这是求出一个割集的方法,如果要求所有的话,我们不断的从刚才求到割集中T中的点再做floodfill直到不能再更新为止然后就可以做完了,这个做法好像是来自WC2007的……和nocow里的不一样,nocow的题解写了一下,会T,也不知道是不是我写的不优美但是这个0.000都可以过的

2018.11.26upd:这个博文的访问量好高= =但是我发现这个算法其实是个假的orz。。。抱歉了各位。。。。
 /*
 ID: ivorysi
 LANG: C++
 TASK: milk6
 */
 #include <iostream>
 #include <cstdio>
 #include <cstring>
 #include <algorithm>
 #include <queue>
 #include <set>
 #include <vector>
 #include <string.h>
 #define siji(i,x,y) for(int i=(x);i<=(y);++i)
 #define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
 #define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
 #define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
 #define inf 0x7fffffff
 #define ivorysi
 #define mo 97797977
 #define hash 974711
 #define base 47
 #define pss pair<string,string>
 #define MAXN 30005
 #define fi first
 #define se second
 #define pii pair<int,int>
 using namespace std;
 struct node {
     int to,next,val;
 }edge[];
 ],sum=,n,m;
 void add(int u,int v,int c) {
     edge[++sum].to=v;
     edge[sum].val=c;
     edge[sum].next=head[u];
     head[u]=sum;
 }
 void addtwo(int u,int v,int c) {
     add(u,v,c);
     add(v,u,);
 }
 ],gap[],used[];
 int sap(int u,int aug) {
     if(u==n) return aug;
     ,dmin=n-;
     for(int i=head[u];i;i=edge[i].next) {
         int v=edge[i].to;
         ) {
             ==dis[u]) {
                 int t=sap(v,min(edge[i].val,aug-flow));
                 flow+=t;
                 edge[i].val-=t;
                 edge[i^].val+=t;
                 ]>=n) return flow;
                 if(flow==aug) break;
             }
             dmin=min(dmin,dis[v]);
         }
     }
     if(!flow) {
         --gap[dis[u]];
         ) dis[]=n;
         dis[u]=dmin+;
         ++gap[dis[u]];
     }
     return flow;
 }
 void init() {
     scanf("%d%d",&n,&m);
     int u,v,c;
     siji(i,,m) {
         scanf("%d%d%d",&u,&v,&c);
         used[u]=;used[v]=;
         addtwo(u,v,c);
     }
 }
 ],num=inf,lay=;
 vector<int> ans,temp,list;
 void dfs(int u) {//floodfill
     if(s[u]) return;
     s[u]=;++lay;
     for(int i=head[u];i;i=edge[i].next) {
         ) {
             dfs(edge[i].to);
         }
     }
 }
 void solve() {
     init();
     ;
     ]<n) {
         mincut+=sap(,inf);
     }
     siji(i,,n) {
         ) {
             ++lay;s[i]=;
         }
     }
     dfs();
     ) num=;
     while(lay<n) {
         ) break;
         siji(i,,n) {
             if(s[i]) {
                 for(int j=head[i];j;j=edge[j].next) {
                     == && !s[edge[j].to]) {
                         temp.push_back(j/);
                         list.push_back(edge[j].to);
                     }
                 }
             }
         }
         ) break;//再也找不到最小割就退出
         if(temp.size()<num) {
             num=temp.size();
             ans=temp;
             sort(ans.begin(),ans.end());
         }
         else if(temp.size()==num) {
             sort(temp.begin(),temp.end());
             ;
             xiaosiji(i,,num) {
                 ;break;}
             }
             if(flag) ans=temp;
         }
         xiaosiji(i,,list.size()) {
             dfs(list[i]);
         }
         temp.clear();
     }
     printf("%d %d\n",mincut,num);
     xiaosiji(i,,num) {
         printf("%d\n",ans[i]);
     }
 }
 int main(int argc, char const *argv[])
 {
 #ifdef ivorysi
     freopen("milk6.in","r",stdin);
     freopen("milk6.out","w",stdout);
 #else
     freopen("f1.in","r",stdin);
 #endif
     solve();
     ;
 }
 

USACO 4.4 Pollutant Control (网络流求最小割割集)的更多相关文章

  1. 【BZOJ1391】Order(网络流,最小割)

    [BZOJ1391]Order(网络流,最小割) 题面 BZOJ权限题... 良心洛谷 题目描述 有N个工作,M种机器,每种机器你可以租或者买过来. 每个工作包括若干道工序,每道工序需要某种机器来完成 ...

  2. 【BZOJ3144】切糕(网络流,最小割)

    [BZOJ3144]切糕(网络流,最小割) 题面 BZOJ 题解 这样的类型很有趣 先不考虑相邻距离差不能超过\(D\)的限制 我们考虑答案,显然就是在每个位置选一个最小的高度割就行了 化成最小割的模 ...

  3. sw算法求最小割学习

    http://  blog.sina.com.cn/s/blog_700906660100v7vb.html 转载:http://www.cnblogs.com/ylfdrib/archive/201 ...

  4. poj 3469 Dual Core CPU【求最小割容量】

    Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 21453   Accepted: 9297 ...

  5. BZOJ_1001_狼抓兔子_(平面图求最小割+对偶图求最短路)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1001 1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec   ...

  6. HDU - 3035 War(对偶图求最小割+最短路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3035 题意 给个图,求把s和t分开的最小割. 分析 实际顶点和边非常多,不能用最大流来求解.这道题要用 ...

  7. 【BZOJ2229】[ZJOI2011]最小割(网络流,最小割树)

    [BZOJ2229][ZJOI2011]最小割(网络流,最小割树) 题面 BZOJ 洛谷 题解 戳这里 那么实现过程就是任选两点跑最小割更新答案,然后把点集划分为和\(S\)联通以及与\(T\)联通. ...

  8. 【CF331E】Biologist(网络流,最小割)

    [CF331E]Biologist(网络流,最小割) 题面 洛谷 翻译: 有一个长度为\(n\)的\(01\)串,将第\(i\)个位置变为另外一个数字的代价是\(v_i\). 有\(m\)个要求 每个 ...

  9. [ZJOI2011]最小割 & [CQOI2016]不同的最小割 分治求最小割

    题面: [ZJOI2011]最小割 [CQOI2016]不同的最小割 题解: 其实这两道是同一道题.... 最小割是用的dinic,不同的最小割是用的isap 其实都是分治求最小割 简单讲讲思路吧 就 ...

随机推荐

  1. 5 Kafka 应用问题经验积累

    16.Kafka 配置文件同步 为了给kafka的进程添加GC日志信息,方便在以后重启的时候,加入GC日志: 修改bin/kafka-server-start.sh: export KAFKA_OPT ...

  2. Mongodb 笔记01 MongoDB 简介、MongoDB基础知识、启动和停止MongoDB

    MongoDB 简介 1. 易于使用:没有固定的模式,根据需要添加和删除字段更加容易 2. 易于扩展:MongoDB的设计采用横向扩展.面向文档的数据模型使它能很容易的再多台服务器之间进行分割.自动处 ...

  3. RHEL-7.0重置root密码

    RHCE考试第一个环节就是重置root密码,然而7系列与6系列又存在着很大的不同.以下为RHEL-7.0系统对root密码重置的步骤! 1.开机出现引导菜单时按下e键    2.找到linux16行, ...

  4. 六、强大的 Stream API

    一.了解 Stream Java8中有两大最为重要的改变.第一个是 Lambda 表达式:另外一个则是 Stream API(java.util.stream.*).Stream 是 Java8 中处 ...

  5. markdown里的多层次列表项

    markdown里的多层次列表项 编写python的docstrng太多, 有时候就搞混淆了层次化列表项在博客或者随笔里的规则. docstirng里, 仅用两个空格的缩进就可以实现. 博客里通常是一 ...

  6. golang sql.DB

    数据库 sql.DB连接池需知: sql.DB内置连接池,连接不足时会自动创建新连接,新创建的连接使用sql.Open()时传入的dsn来构造. sql.DBClose时只会关闭连接池中的连接,未归还 ...

  7. Donald Ervin Knuth:最年轻的图灵奖高德纳

    高德纳(Donald Ervin Knuth,1938年),美国著名计算机科学家,斯坦福大学电脑系荣誉教授.高德纳教授被誉为现代计算机科学的鼻祖,在计算机科学及数学领域发表了多部 具广泛影响的论文和著 ...

  8. 如何使用Defender优雅的管理权限?

    何为权限管理 权限管理已经不知不觉深入到了我们生活的每一个角落,例如地铁进站的闸机,高速公路上的过路费,停车场的杠杆等等等等. 作为一名开发人员,权限二字对我们的映像更加深刻,无论任何系统,都多多少少 ...

  9. [JL]最后的晚餐 动态规划(DP) codevs5318

    [JL]最后的晚餐 TimeLimit:1000MS  MemoryLimit:1000KB 64-bit integer IO format:%lld Problem Description [题库 ...

  10. Pool thread stack traces: Thread[C3P0PooledConnectionPoolManager[identityToken->原因解决办法

    今天本地连接测试库测试,发现早上还是好的,下午就崩了,报这个错,使用的是c3po连接池: , 纠结了好久,发现是数据库连接用光了,很多人都在连,果断换了本地库,好使了,看百度说把macPoolSizz ...