Description

link

题意概述:给一张图,每条边有边权,求让点 \(1\) 和点 \(n\) 不连通的“最小破坏边权和” 和 “在此基础上的最小破坏边数”

边数 \(\leq 1000\) ,点数 \(\leq 32\)

Solution

\[Begin
\]

其实看出来这个可以用最小割做挺显然的

然后第二问的做法就有点点技巧了

我们把图中的每一条边的边权 \(w_i\) 转化成 \(a \times w_i+1\)

其中\(a\) > \(1000\)

然后我们跑最大流,求得的 \(ans/a\) 就是最小割,然后 \(ans \% a\) 就是边数

这里特别好理解的

\[Finish
\]

Code

#include<bits/stdc++.h>
using namespace std;
#define int long long
namespace yspm{
inline int read()
{
int res=0,f=1; char k;
while(!isdigit(k=getchar())) if(k=='-') f=-1;
while(isdigit(k)) res=res*10+k-'0',k=getchar();
return res*f;
}
const int N=1e4+10,M=1e5+10;
struct node{int nxt,to,lim;}e[M<<1];
int head[N],dep[N],ans,s,t,cnt=1,n,m,a=1002;
inline void add(int u,int v,int w)
{
e[++cnt].nxt=head[u],e[cnt].lim=w; e[cnt].to=v;
return head[u]=cnt,void();
}
queue<int>q;
inline bool bfs()
{
memset(dep,-1,sizeof(dep)); dep[s]=0;
while(q.size()) q.pop(); q.push(s);
while(!q.empty())
{
int fr=q.front(); q.pop();
for(int i=head[fr];i;i=e[i].nxt)
{
int tr=e[i].to;
if(dep[tr]==-1&&e[i].lim) dep[tr]=dep[fr]+1,q.push(tr);
}
}
return dep[t]!=-1;
}
inline int dfs(int now,int in)
{
if(now==t) return in; int out=0;
for(int i=head[now];i&&in;i=e[i].nxt)
{
int tr=e[i].to;
if(e[i].lim&&dep[tr]==dep[now]+1)
{
int res=dfs(tr,min(in,e[i].lim));
in-=res; out+=res; e[i].lim-=res;
e[i^1].lim+=res;
}
} if(!out) dep[now]=-1; return out;
}
signed main()
{
n=read(),m=read(); s=1,t=n;
for(int i=1,u,v,w;i<=m;++i)
{
u=read(); v=read(); w=read();
add(u,v,w*a+1); add(v,u,0);
}
while(bfs()) ans+=dfs(s,1e17);
printf("%lld %lld\n",ans/a,ans%a);
return 0;
}
}
signed main(){return yspm::main();}

没怎么压行,应该挺可读的

LGOJ1344 追查坏牛奶的更多相关文章

  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. 【COGS】894. 追查坏牛奶

    http://cojs.tk/cogs/problem/problem.php?pid=894 题意:n个点m条边的加权网络,求最少边数的按编号字典序最小的最小割.(n<=32, m<=1 ...

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

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

  8. Luogu1344 追查坏牛奶 最小割

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

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

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

随机推荐

  1. Compare/ContrastEssay你真的会写了吗?

    Compare/Contrast Essay也是留学生们常遇到的一种作业类型,但是很多留学生不知道怎么写.本文HotEssay为大家整理了Compare/Contrast Essay写作方法,希望对大 ...

  2. 吴裕雄--天生自然JAVA SPRING框架开发学习笔记:Spring JDBCTemplate简介

    Spring 框架针对数据库开发中的应用提供了 JDBCTemplate 类,该类是 Spring 对 JDBC 支持的核心,它提供了所有对数据库操作功能的支持. Spring 框架提供的JDBC支持 ...

  3. Elasticsearch 使用集群

    章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...

  4. spring boot集成mybatis(1)

    Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...

  5. chrome浏览器安装vue调试器vue-devtools

    chrome浏览器安装vue调试器vue-devtools https://blog.csdn.net/zhangjnwei/article/details/76693053

  6. multi-layer perceptrons, MLP)模型,CvANN_MLP。

    #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <ope ...

  7. 高次同余方程 $BSGS$

    第一篇\(Blog\)... 还是决定把\(luogu\)上的那篇搬过来了. BSGS,又名北上广深 它可以用来求\(a^x \equiv b (mod \ n)\)这个同余方程的一个解,其中\(a, ...

  8. linux 用户与文件常用命令

    用户与文件 su :切换到超级用户 su - l chesney : 切换到chesney用户 sudo usermod -G sudo -a chesney:把chesney 加入到sudo组 su ...

  9. 标准库模块——json模块

    将Python数据类型转换为其他代码格式叫做(序列化),而json就是在各个代码实现转换的中间件. 序列化要求: 1. 只能有int,str,bool,list,dict,tuple的类型支持序列化. ...

  10. VUE.js入门学习(1)-起步

    1.hello world <div id="app">{{content}}</div>var app = new Vue({ el:'#app', da ...