POJ 1966 Cable TV Network 枚举最小割
2014-04-19 10:27
274 查看
点击打开链接
Cable TV Network
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
Sample Output
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
给你一个无向图,让你求这个图的安全系数f。
1.如果f为n,不管删除多少点,剩下的点都是连通的。
2.f为删除最少的点使得剩下的图不连通。
求最小点割集。
建图:
将每个点拆成两个,i和i',它们之间的流量为1.
如果两个点相连,则u'->v流量为inf,因为是无向图,所以v'->u流量也是inf。
源点是n',枚举汇点求最大流。
如果最大流都是inf,那么此图就是连通的,那么f就是n。
Cable TV Network
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 3740 | Accepted: 1753 |
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
给你一个无向图,让你求这个图的安全系数f。
1.如果f为n,不管删除多少点,剩下的点都是连通的。
2.f为删除最少的点使得剩下的图不连通。
求最小点割集。
建图:
将每个点拆成两个,i和i',它们之间的流量为1.
如果两个点相连,则u'->v流量为inf,因为是无向图,所以v'->u流量也是inf。
源点是n',枚举汇点求最大流。
如果最大流都是inf,那么此图就是连通的,那么f就是n。
//1292K 47MS #include<stdio.h> #include<string.h> #include<queue> #include<algorithm> #define inf 0x3f3f3f3f using namespace std; int n,m; int map[300][300],pre[300],flow[300][300],p[300],a[300]; int EK(int s,int t) { int sum=0; int m=2*s+2; queue<int>q; memset(flow,0,sizeof(flow)); for(;;) { memset(a,0,sizeof(a));//记录残量 a[s]=inf; q.push(s); while(!q.empty()) { int u=q.front(); q.pop(); for(int i=0; i<m; i++) if(!a[i]&&map[u][i]>flow[u][i]) { p[i]=u;//记录i的父亲节的是u q.push(i); a[i]=a[u]<map[u][i]-flow[u][i]?a[u]:map[u][i]-flow[u][i]; } } if(!a[t])break;//如果残量是0的话,就找到最大流 for(int i=t; i!=s; i=p[i])//每条路加上最小残量 { flow[p[i]][i]+=a[t]; flow[i][p[i]]-=a[t]; } sum+=a[t];//记录流量 } return sum; } int main() { int a,b; while(scanf("%d%d",&n,&m)!=EOF) { memset(map,0,sizeof(map)); memset(p,0,sizeof(p)); for(int i=0;i<n;i++) map[i][i+n]=1; while(m--) { scanf(" (%d,%d)",&a,&b); map[a+n][b]=inf; map[b+n][a]=inf; } int ans=inf; for(int i=1;i<n;i++) ans=min(ans,EK(n,i)); if(ans==inf)ans=n; printf("%d\n",ans); } return 0; }
相关文章推荐
- POJ 1966--Cable TV Network【最小割 && 枚举终点起点】
- poj 1966 Cable TV Network 【枚举源汇 求解 无向图最小割】
- POJ 3925 Minimal Ratio Tree(枚举+最小生成树)
- POJ 2784 Buy or Build(二进制枚举 + 最小生成树)
- POJ 1681 Painter's Problem (高斯消元 枚举自由变元求最小的步数)
- POJ 1966 无向图点联通度 最小割
- POJ 3301 (坐标变换、三分枚举计算 点集最小正方形覆盖)
- poj 1815 Friendship (最小割+拆点+枚举)
- 点连通度 边连通度 最大流最小割 最小割点集 最小割边集 & POJ 1966 Cable TV Network
- poj 1815 Friendship 【最小割点集】【枚举删点 + 求解最小字典序】
- POJ 1966 最大流最小割...
- POJ 1815 最大流最小割枚举找割点
- POJ 1966 Cable TV Network【无向图点连通度 最小割 E-K算法求最大流】
- poj 2010 Moo University - Financial Aid(优先队列(最小堆)+ 贪心 + 枚举)
- [最小点割集]poj 1815 #贪心枚举
- poj3522 Slim Span 最长边与最短边差值最小的生成树,kruskal算法 + 暴力枚举
- poj--1815--Friendship(最小割点集)(枚举求最小字典序)
- Poj(2784),二进制枚举最小生成树
- poj 1815 Friendship (最小割+拆点+枚举)
- poj 1966 Cable TV Network 无向图最小割