http://cojs.tk/cogs/problem/problem.php?pid=894

题意:n个点m条边的加权网络,求最少边数的按编号字典序最小的最小割。(n<=32, m<=1000)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Gr {
static const int N=33, M=1005, oo=~0u>>1;
struct E { int next, from, to, cap; }e[M<<1];
int ihead[N], cnt, d[N], p[N], gap[N], cur[N];
Gr() { memset(ihead, 0, sizeof ihead); cnt=1; }
Gr & operator=(const Gr &g) {
memcpy(ihead, g.ihead, sizeof g.ihead);
memcpy(e, g.e, sizeof g.e);
cnt=g.cnt;
return *this;
}
void add(int u, int v, int cap) {
e[++cnt]=(E){ihead[u], u, v, cap}; ihead[u]=cnt;
e[++cnt]=(E){ihead[v], v, u, 0}; ihead[v]=cnt;
}
ll isap(int s, int t, int n) {
for(int i=0; i<=n; ++i) d[i]=0, gap[i]=0, cur[i]=ihead[i];
gap[0]=n; int u=s, i, f; ll ret=0;
while(d[s]<n) {
for(i=cur[u]; i; i=e[i].next) if(e[i].cap && d[e[i].to]+1==d[u]) break;
if(i) {
cur[u]=i; p[e[i].to]=i; u=e[i].to;
if(u==t) {
for(f=oo; u!=s; u=e[p[u]].from) f=min(f, e[p[u]].cap);
for(u=t; u!=s; u=e[p[u]].from) e[p[u]].cap-=f, e[p[u]^1].cap+=f;
ret+=f;
}
}
else {
if(!(--gap[d[u]])) break;
d[u]=n; cur[u]=ihead[u];
for(i=ihead[u]; i; i=e[i].next) if(e[i].cap && d[e[i].to]+1<d[u]) d[u]=d[e[i].to]+1;
++gap[d[u]];
if(u!=s) u=e[p[u]].from;
}
}
return ret;
}
}g, G;
int n, m, arr[Gr::M], tot;
int main() {
freopen("milk6.in", "r", stdin);
freopen("milk6.out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i=1; i<=m; ++i) {
int x, y, cap;
scanf("%d%d%d", &x, &y, &cap);
g.add(x, y, cap*(m+1)+1);
}
ll ans=0, f;
G=g;
f=G.isap(1, n, n);
for(int i=1; i<=m; ++i) {
int id=i<<1, cap=g.e[id].cap;
g.e[id].cap=g.e[id^1].cap=0;
G=g;
ll mn=G.isap(1, n, n);
if(mn+cap==f) arr[++tot]=i, ans+=(cap-1)/(m+1), f=mn;
else g.e[id].cap=cap, g.e[id^1].cap=0;
}
printf("%lld %d ", ans, tot);
for(int i=1; i<=tot; ++i) printf("%d ", arr[i]);
return 0;
}

  

神题...在uoj群被神犇们吊打&裱

= =这么水的usaco training我都不会做= =

首先求最少边的话可以直接将权值变为$w*(m+1)+1$,然后就是最小割。理由很简单,最小割是$\sum_{i为一条割边} (w[i]*(m+1)+1) = (m+1)\sum_{i为一条割边} w[i] + c$首先我们分离出了原来没有改变权值的割,显然这样做$\sum_{i为一条割边} w[i]$是原图的最小割,因为乘上$(m+1)$后始终大于边数,和边数$c$都是常数= =。其次我们在求改变权值后的最小割后,比较完原图最小割后还比较了右边常数$c$,而$c$正是割边数。而$(m+1)$这个乘数也是因为割边数<=m最大可能到了m,可能会影响到原来图上的边权值,所以乘上$(m+1)$来消除影响。

那么现在问题变为求普通的字典序最少的最小割。我们考虑从小到大枚举边然后删边。

如果删掉$i$这条边时,最小割变小的值恰好为$i$改变后的权值,那么显然$i$是割边,此时维护的最小割减小,删掉$i$不恢复。

否则把删掉的边恢复。

【COGS】894. 追查坏牛奶的更多相关文章

  1. 【Luogu1344】追查坏牛奶(最小割)

    [Luogu1344]追查坏牛奶(最小割) 题面 洛谷 题解 裸的最小割,但是要求边的数量最小. 怎么办呢?给每条边的权值额外加上一个很大的值就了. #include<iostream> ...

  2. 洛谷 P1344 [USACO4.4]追查坏牛奶Pollutant Control 解题报告

    P1344 [USACO4.4]追查坏牛奶Pollutant Control 题目描述 你第一天接手三鹿牛奶公司就发生了一件倒霉的事情:公司不小心发送了一批有三聚氰胺的牛奶.很不幸,你发现这件事的时候 ...

  3. USACO Section 4.4 追查坏牛奶Pollutant Control

    http://www.luogu.org/problem/show?pid=1344 题目描述 你第一天接手三鹿牛奶公司就发生了一件倒霉的事情:公司不小心发送了一批有三聚氰胺的牛奶.很不幸,你发现这件 ...

  4. 洛谷 P1344 [USACO4.4]追查坏牛奶Pollutant Control

    题目描述 你第一天接手三鹿牛奶公司就发生了一件倒霉的事情:公司不小心发送了一批有三聚氰胺的牛奶.很不幸,你发现这件事的时候,有三聚氰胺的牛奶已经进入了送货网.这个送货网很大,而且关系复杂.你知道这批牛 ...

  5. USACO 4.4.2 追查坏牛奶 oj1341 网络流最小割问题

    描述 Description 你第一天接手三鹿牛奶公司就发生了一件倒霉的事情:公司不小心发送了一批有三聚氰胺的牛奶.很不幸,你发现这件事的时候,有三聚氰胺的牛奶已经进入了送货网.这个送货网很大,而且关 ...

  6. 【题解】Luogu P1344 [USACO4.4]追查坏牛奶Pollutant Control

    原题传送门 看到这种题,应该一眼就能知道考的是最小割 没错这题就是如此简单,跑两遍最大流(最小割=最大流),一次边权为题目所给,一次边权为1 还有一种优化,优化后只需跑一次最大流,把每条边的权值改成w ...

  7. Luogu1344 追查坏牛奶 最小割

    题目传送门 题意:给出$N$个节点$M$条边的有向图,边权为$w$,求其最小割与达到最小割的情况下割掉边数的最小值.$N \leq 32,M \leq 1000,w\leq 2 \times 10^6 ...

  8. luogu P1344 [USACO4.4]追查坏牛奶Pollutant Control

    传送门 要求断掉某些边使得两个点不连通,显然是最小割 但是要求选的边数尽量少,,, 可以考虑修改边权(容量),即把边权\(c\)改成\(c*(m+1)+1\) 没了 // luogu-judger-e ...

  9. [USACO4.4]追查坏牛奶Pollutant Control

    题目链接:ヾ(≧∇≦*)ゝ Solution: 第一问很好解决,根据网络流:最大流=最小割定理,我们可以轻松求出. 至于第二问,我们不妨把每一条边乘上一个大于1000的数再加上1. 这样的话,对于最小 ...

随机推荐

  1. Sexagenary Cycle(天干地支法表示农历年份)

    Sexagenary Cycle Time Limit: 2 Seconds      Memory Limit: 65536 KB 题目链接:zoj 4669 The Chinese sexagen ...

  2. C# TreeView使用技巧

    节点勾选设置 TreeView树中节点勾选要求: 1.不选中一个节点,则其所有的子节点都不被选中. 2.选中一个节点,则其所有的子节点都被选中. 3.当一个节点的所有子节点都没有被选中时,该节点也没有 ...

  3. java Integer == 比较的小问题

    示例代码: @Test public void testEquals() { Integer a = 127; Integer b = 127; if(a == b) { System.out.pri ...

  4. Win10 VS2015 社区版切换到VS2013社区版 进行维护之前的项目

    前提:当先在Win10 OS 安装了vs2015之后开发Win UAP,之后要维护之前的WP8 版本,安装了VS2013社区版 打开后 1问.Exception from HRESULT: 0x897 ...

  5. hdu 4061 福州赛区网络赛A 数学 ***

    a1/sum #include<cstdio> #include<iostream> #include<algorithm> #include<cstring ...

  6. Unity3d 提示 "The scripts file name does not match the name of the class defined in the script!"的解决办法

    有两个原因,一个是文件的名称和类名不一致 第二个原因是有命名空间, 排除应该是可以修复的

  7. the last lecture

    2008.07.25,CMU教授Randy Pausch教授因癌症去世,仅47岁. 几年之前,当我看到Pausch先生最后一课的视频时,让我震撼. 转眼之间,7年过去了,这7年,让我成长了许多. 7年 ...

  8. 允许webservice远程测试

    System.Web节点下添加 <webServices> <protocols> <add name= "HttpPost"/> <ad ...

  9. python学习-爬虫

    转载自 静觅的博客 最普通下载网页 import urrlib2 response = urllib2.urlopen("http://www.baidu.com") print ...

  10. MFC 丢失MSVCR120D.dll 丢失mfc120ud.dll