传送门

Luogu

解题思路

题目要求的是最小割点集,考虑用最小割来做。

所有边容量为1,直接求最小割?

这样肯定会出错,比如这种情况:



从最左边的点到最右边的点的最小割为2,但是答案是1,只要破坏中间那个点就好了。

所以我们把删点转化为割边。

考虑拆点:方便起见,我们把拆出来的点称作“次点”。

那么对于每个点都向它的次点连一条容量为1的边。

然后对于原图中的边 \(u \to v\),连边 \(u^\prime \to v,v^\prime \to u\),容量都为inf。

也就是我们保证到达一个点的流量只能从原点入,次点出,那么我们割掉他们之间的边,就相当于删掉了这个点。

细节注意事项

  • 源点是输入的源点的次点

参考代码

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#define rg register
using namespace std;
template < class T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) s = s * 10 + c - 48, c = getchar();
s = f ? -s : s;
} const int _ = 10002;
const int __ = 100002;
const int INF = 2147483647; int tot = 1, head[_], nxt[__ << 1], ver[__ << 1], cap[__ << 1];
inline void Add_edge(int u, int v, int d)
{ nxt[++tot] = head[u], head[u] = tot, ver[tot] = v, cap[tot] = d; }
inline void link(int u, int v, int d) { Add_edge(u, v, d), Add_edge(v, u, 0); } int n, m, s, t, dep[_]; inline int bfs() {
static queue < int > Q;
memset(dep + 1, 0, sizeof (int) * 2 * n);
dep[s] = 1, Q.push(s);
while (!Q.empty()) {
int u = Q.front(); Q.pop();
for (rg int i = head[u]; i; i = nxt[i]) {
int v = ver[i];
if (dep[v] == 0 && cap[i] > 0)
dep[v] = dep[u] + 1, Q.push(v);
}
}
return dep[t] > 0;
} inline int dfs(int u, int flow) {
if (u == t) return flow;
for (rg int i = head[u]; i; i = nxt[i]) {
int v = ver[i];
if (dep[v] == dep[u] + 1 && cap[i] > 0) {
int res = dfs(v, min(flow, cap[i]));
if (res) { cap[i] -= res, cap[i ^ 1] += res; return res; }
}
}
return 0;
} inline int Dinic() {
int res = 0;
while (bfs()) while (int d = dfs(s, INF)) res += d;
return res;
} int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
read(n), read(m), read(s), read(t), s += n;
for (rg int i = 1; i <= n; ++i) link(i, i + n, 1);
for (rg int u, v, i = 1; i <= m; ++i)
read(u), read(v), link(u + n, v, INF), link(v + n, u, INF);
printf("%d\n", Dinic());
return 0;
}

完结撒花 \(qwq\)

「USACO5.4」奶牛的电信Telecowmunication的更多相关文章

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

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

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

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

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

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

  4. 题解 P1345 【[USACO5.4]奶牛的电信Telecowmunication】

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

  5. AC日记——[USACO5.4]奶牛的电信Telecowmunication 洛谷 P1345

    [USACO5.4]奶牛的电信Telecowmunication 思路: 水题: 代码: #include <cstdio> #include <cstring> #inclu ...

  6. [USACO5.4]奶牛的电信Telecowmunication(网络流)

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

  7. [Luogu P1345] [USACO5.4]奶牛的电信Telecowmunication (最小割)

    题面 传送门:https://www.luogu.org/problemnew/show/P1345 ] Solution 这道题,需要一个小技巧了解决. 我相信很多像我这样接蒟蒻,看到这道题,不禁兴 ...

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

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

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

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

随机推荐

  1. 【代码总结】PHP面向对象之抽象类

    一.什么是抽象方法? 一个方法如果没有方法体(不使用"{}",直接使用分号结束的方法,才是没有方法体的方法),则这个方法就是抽象方法 1.声明一个方法,不使用{},而直接分号结束 ...

  2. PostgreSQL数据库-分页sql--offset

    select * from users order by score desc limit 3;--取成绩的前3名=====select * from users order by score des ...

  3. From scratch 资源

    neural-network-from-scratch:https://github.com/pangolulu/neural-network-from-scratch rnn-from-scratc ...

  4. Python下opencv使用笔记(十一)(详解hough变换检测直线与圆)

    http://blog.csdn.net/on2way/article/details/47028969 http://blog.csdn.net/mokeding/article/details/1 ...

  5. 2019最新整理JAVA面试题附答案

    本人免费整理了Java高级资料,涵盖了Java.Redis.MongoDB.MySQL.Zookeeper.Spring Cloud.Dubbo高并发分布式等教程,一共30G,需要自己领取.传送门:h ...

  6. C/C++网络编程6——实现基于UDP的服务器端/客户端

    通过前面几节的内容,我们已经可以实现基本的C/S结构的程序了,但是当多个客户端同时向服务器端请求服务时,服务器端只能按顺序一个一个的服务,这种情况下,客户端的用户是无法忍受的.所以虚实现并发的服务器端 ...

  7. js学习:函数

    概述 函数的声明 JavaScript 有三种声明函数的方法 function 命令 function命令声明的代码区块,就是一个函数.function命令后面是函数名,函数名后面是一对圆括号,里面是 ...

  8. ubuntu 更改pip默认源

    mkdir ~/.pip vim ~/.pip/pip.conf [global] timeout = 6000 https://pypi.tuna.tsinghua.edu.cn/simple 保存 ...

  9. 吴裕雄--天生自然数据结构与算法:java代码实现常用数据结构——链表Linked List

    class Node{ // 定义节点类 private String data ; // 保存节点内容 private Node next ; // 表示保存下一个节点 public Node(St ...

  10. Caffe2 的基本数据结构(Basics of Caffe2 - Workspaces, Operators, and Nets)[4]

    这篇文章主要介绍Caffe2的基本数据结构: Workspaces Operators Nets 在开始之前最好先阅读以下Intro Turorial 首先,导入caffe2.其中core和works ...