原题链接

最小割点数转换成最小割边数的模板题(不过这数据好小)。

每个点拆成两个点,连一条容量为\(1\)的边,原图的边容量定为\(+\infty\),然后跑最大流即可。

这里用的是\(Dinic\)。

#include<cstdio>
#include<cstring>
using namespace std;
const int N = 220;
const int M = 5e3;
int fi[N], di[M], ne[M], da[M], de[N], q[N], cu[N], l = 1, st, ed;
inline int re()
{
int x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
inline void add(int x, int y, int z)
{
di[++l] = y;
da[l] = z;
ne[l] = fi[x];
fi[x] = l;
di[++l] = x;
da[l] = 0;
ne[l] = fi[y];
fi[y] = l;
}
inline int minn(int x, int y){ return x < y ? x : y; }
bool bfs()
{
int i, x, y, head = 0, tail = 1;
memset(de, 0, sizeof(de));
q[1] = st;
de[st] = 1;
while (head ^ tail)
{
x = q[++head];
for (i = fi[x]; i; i = ne[i])
if (!de[y = di[i]] && da[i] > 0)
{
de[y] = de[x] + 1;
if (!(y ^ ed))
return true;
q[++tail] = y;
}
}
return false;
}
int dfs(int x, int k)
{
if (!(x ^ ed))
return k;
int mi, y;
for (int &i = cu[x]; i; i = ne[i])
if (!(de[y = di[i]] ^ (de[x] + 1)) && da[i] > 0)
{
mi = dfs(y, minn(k, da[i]));
if (mi > 0)
{
da[i] -= mi;
da[i ^ 1] += mi;
return mi;
}
}
return 0;
}
int main()
{
int i, n, m, x, y, s = 0;
n = re();
m = re();
st = re() + n;
ed = re();
for (i = 1; i <= n; i++)
add(i, i + n, 1);
for (i = 1; i <= m; i++)
{
x = re();
y = re();
add(x + n, y, 1e9);
add(y + n, x, 1e9);
}
while (bfs())
{
for (i = 1; i <= (n << 1); i++)
cu[i] = fi[i];
for (; (x = dfs(st, 1e9)) > 0; s += x);
}
printf("%d", s);
return 0;
}

洛谷1345 [USACO5.4]奶牛的电信Telecowmunication的更多相关文章

  1. 洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication【最小割】分析+题解代码

    洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication[最小割]分析+题解代码 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流. ...

  2. 洛谷——P1345 [USACO5.4]奶牛的电信Telecowmunication

    P1345 [USACO5.4]奶牛的电信Telecowmunication 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮 ...

  3. 洛谷1345 [Usaco5.4]奶牛的电信

    题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...

  4. 洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication

    题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...

  5. 洛谷P13445 [USACO5.4]奶牛的电信Telecowmunication(网络流)

    题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...

  6. 洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication(最小割)

    题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...

  7. 洛谷 P1345 [USACO5.4]奶牛的电信Telecowmunication

    题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...

  8. 洛谷$P1345\ [USACO5.4]$ 奶牛的电信$Telecowmunication$ 网络流

    正解:最小割 解题报告: 传送门$QwQ$ $QwQ$好久没做网络流了来复健下. 这个一看就很最小割趴?考虑咋建图?就把点拆成边权为$1$的边,然后原有的边因为不能割所以边权为$inf$. 然后跑个最 ...

  9. 洛谷P1345 [USACO5.4]奶牛的电信 [最小割]

    题目传送门 奶牛的电信 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,..., ...

随机推荐

  1. linux安装redis标准流程-按这个来

    1.将下载好的压缩包放到/usr/local目录下# tar xzf redis-3.2.9.tar.gz # cd redis-3.2.9 # make 提示错误 make: cc: Command ...

  2. 使用phpAnalysis打造PHP应用非侵入式性能分析器

    使用phpAnalysis打造PHP应用非侵入式性能分析器,查找PHP性能瓶颈. 什么是phpAnalysis phpAnalysis是一款轻量级非侵入式PHP应用性能分析器,适用于开发.测试及生产环 ...

  3. erlang遍历目录

    {ok, Cwd} = file:get_cwd(). Filelist = filelib:fold_files( Cwd, ".*", true, fun(File, Acc) ...

  4. 为嵌入式全志V3s荔枝派板卡添加USB MT7601U(小米随身WIFI)驱动

    折腾了了一天终于scan出环境热点了,感觉本来挺简单的事情,网上教程一大把还费了一天的劲,很丧.不过网上教程虽多,但是还还是有些不同之处的,现在特意总结一下 全志V3s荔枝派板卡 添加该驱动的过程. ...

  5. [转]Java事件处理机制- 事件监听器的四种实现方式

    原文来自http://stefan321.iteye.com/blog/345221 自身类作为事件监听器 外部类作为事件监听器 匿名内部类作为事件监听器 内部类作为事件监听器 自身类作为事件监听器: ...

  6. java多线程中最佳的实践方案是什么?

    java多线程中最佳的实践方案是什么? 给你的线程起个有意义的名字.这样可以方便找bug或追踪.OrderProcessor, QuoteProcessor or TradeProcessor 这种名 ...

  7. Android 梯形进度条、下载进度条;

    额,Gif有点卡: 梯形.矩形.圆角.背景色.前景色.进度条中的文字都可以改: <?xml version="1.0" encoding="utf-8"? ...

  8. oracle12 安装

    oracle    oracle orcl    orcl

  9. SpringBoot 之静态资源

    boot 的默认的静态资源有多个, 由 ResourceProperties 配置了默认值: private static final String[] CLASSPATH_RESOURCE_LOCA ...

  10. canal 结合 kafka 入门

    1.kafka的安装: 略 2.cannal  配置 使用卡夫卡: 修改  /home/admin/canal-server/conf/canal.properties 2.1 修改canal.ser ...