题目地址:UVA1660 电视网络 Cable TV Network

枚举两个不直接连通的点 \(S\) 和 \(T\) ,求在剩余的 \(n-2\) 个节点中最少去掉多少个可以使 \(S\) 和 \(T\) 不连通,在每次枚举的结构中取 \(min\) 就是本题的答案。

点边转化

把原来无向图中的每个点 \(x\) ,拆成入点 \(x\) 和出点 \(x'\) 。在无向图中删去一个点⇔在网络中断开 \((x,x')\) 。对 \(\forall x \neq S,x \neq T\) 连有向边 \((x,x')\) ,容量为 \(1\) 。对原无向图的每条边 \((x,y)\) ,连有向边 \((x',y),(y',x)\) ,容量为 \(+ \infty\) (防止割断)。

求最小割即可。

#include <bits/stdc++.h>
using namespace std;
const int N = 56, M = 2e4 + 6, inf = 0x3f3f3f3f;
int n, m, s, t;
int a[N*N], b[N*N], d[N<<1];
int Head[N<<1], Edge[M], Leng[M], Next[M], tot;

inline void add(int x, int y, int z) {
    Edge[++tot] = y;
    Leng[tot] = z;
    Next[tot] = Head[x];
    Head[x] = tot;
    Edge[++tot] = x;
    Leng[tot] = 0;
    Next[tot] = Head[y];
    Head[y] = tot;
}

inline bool bfs() {
    memset(d, 0, sizeof(d));
    queue<int> q;
    q.push(s);
    d[s] = 1;
    while (q.size()) {
        int x = q.front();
        q.pop();
        for (int i = Head[x]; i; i = Next[i]) {
            int y = Edge[i], z = Leng[i];
            if (z && !d[y]) {
                q.push(y);
                d[y] = d[x] + 1;
                if (y == t) return 1;
            }
        }
    }
    return 0;
}

inline int dinic(int x, int f) {
    if (x == t) return f;
    int rest = f;
    for (int i = Head[x]; i && rest; i = Next[i]) {
        int y = Edge[i], z = Leng[i];
        if (z && d[y] == d[x] + 1) {
            int k = dinic(y, min(rest, z));
            if (!k) d[y] = 0;
            Leng[i] -= k;
            Leng[i^1] += k;
            rest -= k;
        }
    }
    return f - rest;
}

inline void Cable_TV_Network() {
    for (int i = 0; i < m; i++) {
        char str[20];
        scanf("%s", str);
        a[i] = b[i] = 0;
        int j;
        for (j = 1; str[j] != ','; j++) a[i] = a[i] * 10 + str[j] - '0';
        for (j++; str[j] != ')'; j++) b[i] = b[i] * 10 + str[j] - '0';
    }
    int ans = inf;
    for (s = 0; s < n; s++)
        for (t = 0; t < n; t++)
            if (s != t) {
                memset(Head, 0, sizeof(Head));
                tot = 1;
                int maxf = 0;
                for (int i = 0; i < n; i++)
                    if (i == s || i == t) add(i, i + n, inf);
                    else add(i, i + n, 1);
                for (int i = 0; i < m; i++) {
                    add(a[i] + n, b[i], inf);
                    add(b[i] + n, a[i], inf);
                }
                while (bfs()) {
                    int num;
                    while ((num = dinic(s, inf))) maxf += num;
                }
                ans = min(ans, maxf);
            }
    if (n <= 1 || ans == inf) ans = n;
    cout << ans << endl;
}

int main() {
    while (cin >> n >> m) Cable_TV_Network();
    return 0;
}

UVA1660 电视网络 Cable TV Network的更多相关文章

  1. UVA1660 电视网络 Cable TV Network[拆点+最小割]

    题意翻译 题目大意: 给定一个n(n <= 50)个点的无向图,求它的点联通度.即最少删除多少个点,使得图不连通. 解析 网络瘤拆点最小割. 定理 最大流\(=\)最小割 感性地理解(口胡)一下 ...

  2. 【UVA1660】Cable TV Network

    题目大意:给定一个 N 个点的无向图,求至少删去多少个点可以使得无向图不连通. 题解:学习到了点边转化思想. 根据网络流的知识可知,一个网络的最小割与网络的最大流相等.不过最小割是图的边集,而本题则是 ...

  3. POJ 1966 Cable TV Network

    Cable TV Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4702   Accepted: 2173 ...

  4. POJ 1966 Cable TV Network(顶点连通度的求解)

                               Cable TV Network Time Limit: 1000MS   Memory Limit: 30000K Total Submissi ...

  5. POJ 1966 Cable TV NETWORK(网络流-最小点割集)

                                    Cable TV NETWORK The interconnection of the relays in a cable TV net ...

  6. Cable TV Network 顶点连通度 (最大流算法)

    Cable TV Network 题目抽象:给出含有n个点顶点的无向图,给出m条边.求定点联通度   K 算法:将每个顶点v拆成 v'   v''  ,v'-->v''的容量为1.       ...

  7. UVA 1660 Cable TV Network 电视网络(无向图,点连通度,最大流)

    题意:给一个无向图,求其点连通度?(注意输入问题) 思路: 如果只有1个点,那么输出“1”: 如果有0条边,那么输出“0”: 其他情况:用最大流解决.下面讲如何建图: 图的连通度问题是指:在图中删去部 ...

  8. UVA-1660 Cable TV Network (最小割)

    题目大意:给一张n个点.m条边的无向图,求最小点割集的基数. 题目分析:求无向图最小点割集的基数可以变成求最小割.考虑单源s单汇t的无向图,如果要求一个最小点集,使得去掉这个点集后图不再连通(连通分量 ...

  9. UVA1660 Cable TV Network (无向图的点连通度)

    题意:求一个无向图的点连通度. 把一个点拆成一个入点和一个出点,之间连一条容量为1的有向边,表示能被用一次.最大流求最小割即可. 一些细节的东西:1.源点固定,汇点要枚举一遍,因为最小割割断以后会形成 ...

随机推荐

  1. threading:线程创建、启动、睡眠、退出

    1.方法一:将要执行的函数作为参数传递给threading.Thread() import threading import time def func(n): global count time.s ...

  2. Zabbix Server 自带模板监控无密码MySQL数据库

    Zabbix Server 自带模板监控无密码MySQL数据库 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.  一.安装MariaDB 1>.安装MariaDB  [root ...

  3. Idea使用Maven创建Java Web项目

    最近学到了Java Web项目,使用Idea和Maven创建Java Web的时候遇到了诸多问题,最多的还是404问题.现在记录一下解决方案. 一.使用maven创建一个web项目,这一步网上都有,下 ...

  4. Memcached入门学习

    Memcached入门学习 学习网址:http://www.runoob.com/Memcached/Memcached-tutorial.html

  5. Linux记录-JMX监控JAVA进程

    3.修改xxx.sh 加入export JAVA_OPTS="-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.mana ...

  6. Junit4学习与使用【转】

    参考: http://blog.csdn.net/qqhjqs/article/details/42219037

  7. elasticsearch 通过HTTP RESTful API 操作数据

    1.索引样例数据 下载样例数据集链接 下载后解压到ES的bin目录,然后加载到elasticsearch集群 curl -XPOST 127.0.0.1:9200/bank/account/_bulk ...

  8. hdu 6418(石头剪刀布 **)

    题意是说双方各有剪刀,石头和布的卡片各 a,b,c,a‘,b',c' 张,对方是随机选择,问我方的最大预期得分. 这道题目一开始看到的时候感觉没有头绪,再次读题,发现题目说结果可能是分数,如果是分数的 ...

  9. 编辑距离算法以及它的C#实现

    原文:https://www.cnblogs.com/shihuajie/p/5772173.html 注意,原文中有以下表述不当的地方 “扫描两字符串(n*m级的),如果:str1 == str2[ ...

  10. SQL Server进阶 索引

    create unique index 和create index 的区别? CREATE UNIQUE INDEX ProviderInfo_Id_uindex ON dbo.ProviderInf ...