洛谷1345 [USACO5.4]奶牛的电信Telecowmunication
原题链接
最小割点数转换成最小割边数的模板题(不过这数据好小)。
每个点拆成两个点,连一条容量为\(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的更多相关文章
- 洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication【最小割】分析+题解代码
洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication[最小割]分析+题解代码 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流. ...
- 洛谷——P1345 [USACO5.4]奶牛的电信Telecowmunication
P1345 [USACO5.4]奶牛的电信Telecowmunication 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮 ...
- 洛谷1345 [Usaco5.4]奶牛的电信
题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...
- 洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication
题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...
- 洛谷P13445 [USACO5.4]奶牛的电信Telecowmunication(网络流)
题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...
- 洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication(最小割)
题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...
- 洛谷 P1345 [USACO5.4]奶牛的电信Telecowmunication
题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...
- 洛谷$P1345\ [USACO5.4]$ 奶牛的电信$Telecowmunication$ 网络流
正解:最小割 解题报告: 传送门$QwQ$ $QwQ$好久没做网络流了来复健下. 这个一看就很最小割趴?考虑咋建图?就把点拆成边权为$1$的边,然后原有的边因为不能割所以边权为$inf$. 然后跑个最 ...
- 洛谷P1345 [USACO5.4]奶牛的电信 [最小割]
题目传送门 奶牛的电信 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,..., ...
随机推荐
- Redis 总结精讲 看一篇成高手系统-4
本文围绕以下几点进行阐述 1.为什么使用redis2.使用redis有什么缺点3.单线程的redis为什么这么快4.redis的数据类型,以及每种数据类型的使用场景5.redis的过期策略以及内存淘汰 ...
- linq 实现对象映射
public static string GetPrintList(string data) { string[] _data = data.Split(','); string Order_No = ...
- dapper List SqlBulkCopy
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- 前端-JavaScript1-6——JavaScript之变量类型的转换
6.1 string → number 先来学习一个语句,这个语句和alert差不多,也是弹窗,弹的是输入框: 1 prompt("请输入你的电话","139&qu ...
- Java内存管理之类似-Xms、-Xmx 这些参数的含义
1.堆内存分配:JVM 初始分配的内存由**-Xms** 指定,默认是物理内存的 1/64:JVM 最大分配的内存由**-Xmx** 指定,默认是物理内存的 1/4:默认空余堆内存小于 40% 时,J ...
- ios怎么让状态栏颜色和导航栏背景图片颜色一样
ios7 图片作为导航的背景的话,如果想实现状态栏和导航栏一体化,那么图片高度需要增加22,也就是64,retina是128
- mezzanine的page_menu tag(二)
dict的特性,key可以是None >>> def f(): a=[2,3] return a #函数返回local变量 >>> a=f() >>&g ...
- Dom文本应用-表格隔行间亮样式
效果: 隔行一个颜色,鼠标移上去,被选中的那一行就变颜色,其次,鼠标离开其区域,颜色又变回原来的颜色. 一.表格隔行间亮样式-HTML代码 首先我们要有个表格 <table id='tab1' ...
- FTRL的理解
https://blog.csdn.net/ningyanggege/article/details/81133785
- 微信小程序---setData
data:{ obj:{ name:'hello' } } 对data中obj的name字段进行重新赋值. onLoad: function (option) { var value = 'obj.n ...