【连通图|点连通度】POJ-1966 Cable TV Network
来源:互联网 发布:seo网络营销是什么 编辑:程序博客网 时间:2024/05/16 10:35
Cable TV Network
Time Limit: 1000MS Memory Limit: 30000K
Description
The interconnection of the relays in a cable TV network is bi-directional. The network is connected if there is at least one interconnection path between each pair of relays present in the network. Otherwise the network is disconnected. An empty network or a network with a single relay is considered connected. The safety factor f of a network with n relays is:
1. n, if the net remains connected regardless the number of relays removed from the net.
2. The minimal number of relays that disconnect the network when removed.
For example, consider the nets from figure 1, where the circles mark the relays and the solid lines correspond to interconnection cables. The network (a) is connected regardless the number of relays that are removed and, according to rule (1), f=n=3. The network (b) is disconnected when 0 relays are removed, hence f=0 by rule (2). The network (c) is disconnected when the relays 1 and 2 or 1 and 3 are removed. The safety factor is 2.
Input
Write a program that reads several data sets from the standard input and computes the safety factor for the cable networks encoded by the data sets. Each data set starts with two integers: 0<=n<=50,the number of relays in the net, and m, the number of cables in the net. Follow m data pairs (u,v), u < v, where u and v are relay identifiers (integers in the range 0..n-1). The pair (u,v) designates the cable that interconnects the relays u and v. The pairs may occur in any order.Except the (u,v) pairs, which do not contain white spaces, white spaces can occur freely in input. Input data terminate with an end of file and are correct.
Output
For each data set, the program prints on the standard output, from the beginning of a line, the safety factor of the encoded net.
Sample Input
0 0
1 0
3 3 (0,1) (0,2) (1,2)
2 0
5 7 (0,1) (0,2) (1,3) (1,2) (1,4) (2,3) (3,4)
Sample Output
0
1
3
0
2
Hint
The first data set encodes an empty network, the second data set corresponds to a network with a single relay, and the following three data sets encode the nets shown in figure 1.
Source
Southeastern Europe 2004
题意:给出一个无向图,求该图的点连通度。
思路:求点连通度的问题要转化成网络最大流问题。
首先拆点,比如将u点拆成u’和u”点,然后建立u’->u”的一条容量为1的边。再将原来的u->v的边添加到u”->v’上,容量设置成INF。但是由于该题是无向图,所以v”->u’也要添加容量为INF的边。
求一张图的点连通度,要求出任意两点之间的最小的独立轨1个数。这是因为:
若P(A, B)表示不相邻的两点之间的独立轨的个数,那么显然去掉至少P(A, B)个顶点可以使得图不连通。
定理:(设k为点连通度)
因此,可以固定一个源点,枚举每个汇点求出最大流。这个最大流就是P(A, B)。
代码如下:
/* * ID: j.sure.1 * PROG: * LANG: C++ */#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <ctime>#include <cmath>#include <stack>#include <queue>#include <vector>#include <map>#include <set>#include <string>#include <climits>#include <iostream>#define PB push_back#define LL long longusing namespace std;const int INF = 0x3f3f3f3f;const double eps = 1e-8;/****************************************/const int N = 100 + 5, M = 100*99 + 5;int n, m, tot;int src, sink;int cur[N], head[N], lev[N];int s[N];struct Edge { int u, v, w, next; Edge(){} Edge(int _u, int _v, int _w, int _next): u(_u), v(_v), w(_w), next(_next){}}e[M], ef[M];void add(int u, int v, int w){ ef[tot] = Edge(u, v, w, head[u]); head[u] = tot++; ef[tot] = Edge(v, u, 0, head[v]); head[v] = tot++;}void init(){ memset(head, -1, sizeof(head)); tot = 0; for(int i = 0; i < n; i++) { add(i, i+n, 1); }}bool bfs(){ queue <int> q; memset(lev, -1, sizeof(lev)); lev[src] = 0; q.push(src); while(!q.empty()) { int u = q.front(); q.pop(); for(int i = head[u]; ~i; i = e[i].next) { int v = e[i].v; if(e[i].w && lev[v] == -1) { lev[v] = lev[u] + 1; q.push(v); if(v == sink) return true; } } } return false;}int Dinic(){ int ret = 0; while(bfs()) { memcpy(cur, head, sizeof(cur)); int u = src, top = 0; while(1) { if(u == sink) { int mini = INF, loc; for(int i = 0; i < top; i++) { if(mini > e[s[i]].w) { mini = e[s[i]].w; loc = i; } } for(int i = 0; i < top; i++) { e[s[i]].w -= mini; e[s[i]^1].w += mini; } ret += mini; top = loc; u = e[s[top]].u; } int &i = cur[u]; for(; ~i; i = e[i].next) { int v = e[i].v; if(e[i].w && lev[v] == lev[u] + 1) break; } if(~i) { s[top++] = i; u = e[i].v; } else { if(!top) break; lev[u] = -1; u = e[s[--top]].u; } } } return ret;}void copy(){ for(int i = 0; i < tot; i++) { e[i] = ef[i]; }}int main(){#ifdef J_Sure freopen("000.in", "r", stdin); //freopen("999.out", "w", stdout);#endif while(~scanf("%d%d", &n, &m)) { int u, v; init(); for(int i = 0; i < m; i++) { scanf(" (%d,%d)", &u, &v); add(u+n, v, INF); add(v+n, u, INF); } int ans = INF; src = n; for(int i = 1; i < n; i++) { sink = i; copy(); ans = min(ans, Dinic()); } if(ans == INF) ans = n; printf("%d\n", ans); } return 0;}
- 意即没有公共顶点的路径。 ↩
- 【连通图|点连通度】POJ-1966 Cable TV Network
- poj 1966 Cable TV Network 点连通度
- POJ 1966 Cable TV Network 无向图的点连通度
- POJ1966 Cable TV Network 点连通度
- Cable TV Network- POJ 1966 连通量
- POJ 1966 Cable TV Network 顶点连通度的求解
- POJ 1966 / ZOJ 2182 : Cable TV Network - 顶点连通度
- poj 1966 Cable TV Network 顶点连通度-最大流
- POJ 1966 Cable TV Network(顶点连通度)
- Poj 1966 Cable TV Network【点连通度------最大流Dinic】
- 点连通度 边连通度 最大流最小割 最小割点集 最小割边集 & POJ 1966 Cable TV Network
- POJ 1966--Cable TV Network 【求无向图的点连通度 构造最大流模型 && dinic】
- pku 1966 Cable TV Network(求无向图的点连通度)
- POJ 1966 Cable TV Network(无向图的顶点连通度)
- POJ--1966--Cable TV Network【无向图顶点连通度】
- POJ1966.Cable TV Network——无向图的点连通度
- 【poj1966】Cable TV Network 无向图点连通度(最大流)
- UVA 1660 Cable TV Network [最小割] [图的连通度] [拆点]
- nomount 状态 编录也能查看备份信息--控制文件丢失也是nomount状态?
- 梦中人
- gson<二>
- 安卓平台搭建过程中遇到的问题
- 字符串-03. 字符串的冒泡排序(20)
- 【连通图|点连通度】POJ-1966 Cable TV Network
- 解决Shockwave flash在谷歌浏览器上崩溃的问题
- 智能体2月6号记录
- 谷歌浏览器(Chrome)遇到Flash崩溃的处理办法
- 最小割 Stoer-Wagner 算法
- HDOJ 题目2473 Junk-Mail Filter(并查集,删点)
- [原创]10个人都不坐在自己座位上有多少种可能机率多大
- 字符串-04. 字符串逆序(15)
- 字符串-05. 字符串循环左移(20)