题意

传送门 POJ 1966 Cable TV Network

题解

若无向图不连通,则图中至少存在两个点不连通,则可以枚举这两个点。若两个不同的点 s , t s,t s,t 因为删去某个点集而不连通,那么 s , t s,t s,t 间不存在直接相连的边。问题转化为求解使当前枚举的两个点不连通,需要删除的最小节点数。

使用点边转化的技巧,将割点集转化为割边集。具体而言,将每个节点 x x x 拆成“入点” x x x 与“出点” x ′ x' x′;除了 s , t s,t s,t,其余节点从入点向出点连一条容量为 1 1 1 的边;无向图中的边,转化为两条有向边,对于边 ( x , y ) (x,y) (x,y),从 x ′ x' x′ 向 y y y 连一条容量为 i n f inf inf 的边,以防止其出现在最小割中。最后使用 D i n i c Dinic Dinic 算法求解最小割,更新答案即可。

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 55, maxv = 2 * maxn, maxe = 2 * (maxv + maxn * maxn);
int N, M;
bool G[maxn][maxn];
int tot, head[maxv], to[maxe], cap[maxe], nxt[maxe];
int level[maxv], iter[maxv];inline void add(int x, int y, int c)
{to[++tot] = y, cap[tot] = c, nxt[tot] = head[x], head[x] = tot;to[++tot] = x, cap[tot] = 0, nxt[tot] = head[y], head[y] = tot;
}bool bfs(int s, int t)
{memset(level, -1, sizeof(level));level[s] = 0, iter[s] = head[s];queue<int> q;q.push(s);while (q.size()){int x = q.front();q.pop();for (int i = head[x]; i; i = nxt[i]){int y = to[i], c = cap[i];if (c > 0 && level[y] == -1){level[y] = level[x] + 1, iter[y] = head[y], q.push(y);if (y == t)return 1;}}}return 0;
}int dfs(int x, int t, int f)
{if (x == t)return f;for (int &i = iter[x]; i; i = nxt[i]){int y = to[i], c = cap[i];if (c && level[y] == level[x] + 1){int d = dfs(y, t, min(f, c));if (d){cap[i] -= d, cap[i ^ 1] += d;return d;}elselevel[y] = -1;}}return 0;
}int dinic(int s, int t)
{int flow = 0, f = 0;while (bfs(s, t))while (f = dfs(s, t, inf))flow += f;return flow;
}int main()
{while (~scanf("%d%d", &N, &M)){memset(G, 0, sizeof(G));for (int i = 0, x, y; i < M; ++i)scanf(" (%d,%d)", &x, &y), G[x][y] = G[y][x] = 1;int res = inf;for (int x = 0; x < N; ++x)for (int y = x + 1; y < N; ++y){if (G[x][y])continue;memset(head, 0, sizeof(head));tot = 1;int s = N + x, t = y;for (int i = 0; i < N; ++i)if (i != x && i != y)add(i, N + i, 1);for (int i = 0; i < N; ++i)for (int j = i + 1; j < N; ++j)if (G[i][j])add(N + i, j, inf), add(N + j, i, inf);res = min(res, dinic(s, t));}printf("%d\n", res == inf ? N : res);}return 0;
}

POJ 1966 枚举 + Dinic相关推荐

  1. POJ 1966 Cable TV Network (最大流最小割)

    $ POJ~1966~Cable~TV~Network $ $ solution: $ 第一眼可能让人很难下手,但本就是冲着网络流来的,所以我们直接一点.这道题我们要让这个联通图断开,那么势必会有两个 ...

  2. [POJ 1966] Cable TV Network

    [题目链接] http://poj.org/problem?id=1966 [算法] 拆点 + 最小割 [代码] #include <algorithm> #include <bit ...

  3. POJ - 1966 Cable TV Network(最小割-最大流)

    题目链接:点击查看 题目大意:给定一张无向图,求最少去掉多少个点,可以使图不连通 题目分析:让图不连通,也就是让图分成两个部分,这样题目就转换成了最小割的问题了,不过最小割问题是要求最小割边,所以我们 ...

  4. poj 1966 Cable TV Network 顶点连通度

    题目链接 给一个图, n个点m条边, 求至少去掉多少个点可以使得图不再联通. 随便指定一个点为源点, 枚举其他点为汇点的情况, 跑网络流, 求其中最小的情况. 如果最后ans为inf, 说明是一个完全 ...

  5. POJ 3713 枚举 + Tarjan 割点

    题意 传送门 POJ 3713 题解 白书里归到最大流最小割,Emmmm没有找到复杂度比较低的方法.虽然通道节点不相交可以转化为节点容量为 1,通过拆成 2 个节点并连边转化成最大流问题,但要枚举每一 ...

  6. POJ 1966 求无向图点连通度

    思路: n^2枚举(必须要n^2枚举啊)+拆点 特此嘲讽网上诸多垃圾题解,你们许多都是错的 -yyh //By SiriusRen #include <queue> #include &l ...

  7. Cable TV Network POJ - 1966 最大流最小割定理 点边转化

    最大流最小割定理 任何一个网络的最大流量等于最小割中边的容量之和 即最大流等于最小割 点边转化 节点可以拆为入点和出点 把点的属性添加到入点和出点之间的边上 图的边也可以分两截 在中间加一个节点 把边 ...

  8. POJ 1966 Cable TV Network【无向图点连通度 最小割 E-K算法求最大流】

    题目描述: 给你一个无向图,问你最少删掉几个点,使这个图成不连通. 解题报告: 概念 (1)一个具有 N 个顶点的图,在去掉任意 k-1 个顶点后 (1<=K<=N) 所得的子图仍连通, ...

  9. POJ 3276 枚举+差分?

    题意: 思路: 先枚举一下k 贪心:如果当前是B那么就翻 差分一下序列 mod2 就OK了 //By SiriusRen #include <cstdio> #include <cs ...

最新文章

  1. docusign文档打不开_怎样查看 docusign pdf 电子签名
  2. Caddy Web服务器QUIC部署
  3. 华强北耳机版本太多,不知道如何选购?
  4. Could not find support-media-compat.aar
  5. PHP红黑源码,红黑树的实现源码(第二次修订版)
  6. ASP.NET导出word实例
  7. 御用导航提示提醒_汽车导航,离线和在线哪个好用?两者的区别分析
  8. 题目1131:合唱队形(最长递增子序列进阶)
  9. c语言删除功能,程序的删除功能有问题,不知怎么改
  10. 20191209每日一句
  11. 配置阿里云矢量图标2021
  12. CentOs7下Zabbix安装教程——zabbix server安装
  13. 超级实用springBoot学习
  14. Mac 锁屏防止断网、睡眠、注销登录
  15. 原 《老路用得上的商学课》76-80学习笔记
  16. 计算机房的正常温度和湿度,什么是机房温度、湿度标准?
  17. ERROR: pip‘s dependency resolver does not currently take into account all the packages that are ....
  18. Docker 学习前置,网络IP地址以及交互
  19. HDWiki的兼容性问题
  20. 使用扩展卡尔曼滤波(EKF)进行AHRS九轴姿态融合

热门文章

  1. C/C++解析tar文件
  2. 2022,不会SpringBoot,后端真的不好找工作
  3. 采用sql存储的方法保存所爬取的豆瓣电影
  4. search(1)- elasticsearch结构概念
  5. 信用卡欺诈行为检测_在无监督学习的情况下检测欺诈行为
  6. 极域电子书包windows-ios界面展示与使用方法
  7. 学习笔记之DC-DC
  8. realvnc linux客户端,Linux_设定RealVNC服务器
  9. No cached version of com.facebook.android:facebook-android-sdk:8.1.0 available for offline mode
  10. Win10 VS2015 error LNK1104: 无法打开文件“opencv_world331.lib”