POJ 2117 求无向图的割点
2015-04-01 23:51
281 查看
Electricity
Description
Blackouts and Dark Nights (also known as ACM++) is a company that provides electricity. The company owns several power plants, each of them supplying a small area that surrounds it. This organization brings a lot of problems - it often happens that there is not enough power in one area, while there is a large surplus in the rest of the country.
ACM++ has therefore decided to connect the networks of some of the plants together. At least in the first stage, there is no need to connect all plants to a single network, but on the other hand it may pay up to create redundant connections on critical places - i.e. the network may contain cycles. Various plans for the connections were proposed, and the complicated phase of evaluation of them has begun.
One of the criteria that has to be taken into account is the reliability of the created network. To evaluate it, we assume that the worst event that can happen is a malfunction in one of the joining points at the power plants, which might cause the network to split into several parts. While each of these parts could still work, each of them would have to cope with the problems, so it is essential to minimize the number of parts into which the network will split due to removal of one of the joining points.
Your task is to write a software that would help evaluating this risk. Your program is given a description of the network, and it should determine the maximum number of non-connected parts from that the network may consist after removal of one of the joining points (not counting the removed joining point itself).
Input
The input consists of several instances.
The first line of each instance contains two integers 1 <= P <= 10 000 and C >= 0 separated by a single space. P is the number of power plants. The power plants have assigned integers between 0 and P - 1. C is the number of connections. The following C lines of the instance describe the connections. Each of the lines contains two integers 0 <= p1, p2 < P separated by a single space, meaning that plants with numbers p1 and p2 are connected. Each connection is described exactly once and there is at most one connection between every two plants.
The instances follow each other immediately, without any separator. The input is terminated by a line containing two zeros.
Output
The output consists of several lines. The i-th line of the output corresponds to the i-th input instance. Each line of the output consists of a single integer C. C is the maximum number of the connected parts of the network that can be obtained by removing one of the joining points at power plants in the instance.
Sample Input
Sample Output
Source
CTU Open 2004
题意:给定一个无向图,求删除一个节点后,使得图的连通分量的数量最多;
解题思路:
1.求割点,答案=初始图的连通分量数+割边数;
2.if(m==0) ans=n-1;
Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 4332 | Accepted: 1419 |
Blackouts and Dark Nights (also known as ACM++) is a company that provides electricity. The company owns several power plants, each of them supplying a small area that surrounds it. This organization brings a lot of problems - it often happens that there is not enough power in one area, while there is a large surplus in the rest of the country.
ACM++ has therefore decided to connect the networks of some of the plants together. At least in the first stage, there is no need to connect all plants to a single network, but on the other hand it may pay up to create redundant connections on critical places - i.e. the network may contain cycles. Various plans for the connections were proposed, and the complicated phase of evaluation of them has begun.
One of the criteria that has to be taken into account is the reliability of the created network. To evaluate it, we assume that the worst event that can happen is a malfunction in one of the joining points at the power plants, which might cause the network to split into several parts. While each of these parts could still work, each of them would have to cope with the problems, so it is essential to minimize the number of parts into which the network will split due to removal of one of the joining points.
Your task is to write a software that would help evaluating this risk. Your program is given a description of the network, and it should determine the maximum number of non-connected parts from that the network may consist after removal of one of the joining points (not counting the removed joining point itself).
Input
The input consists of several instances.
The first line of each instance contains two integers 1 <= P <= 10 000 and C >= 0 separated by a single space. P is the number of power plants. The power plants have assigned integers between 0 and P - 1. C is the number of connections. The following C lines of the instance describe the connections. Each of the lines contains two integers 0 <= p1, p2 < P separated by a single space, meaning that plants with numbers p1 and p2 are connected. Each connection is described exactly once and there is at most one connection between every two plants.
The instances follow each other immediately, without any separator. The input is terminated by a line containing two zeros.
Output
The output consists of several lines. The i-th line of the output corresponds to the i-th input instance. Each line of the output consists of a single integer C. C is the maximum number of the connected parts of the network that can be obtained by removing one of the joining points at power plants in the instance.
Sample Input
3 3 0 1 0 2 2 1 4 2 0 1 2 3 3 1 1 0 0 0
Sample Output
1 2 2
Source
CTU Open 2004
题意:给定一个无向图,求删除一个节点后,使得图的连通分量的数量最多;
解题思路:
1.求割点,答案=初始图的连通分量数+割边数;
2.if(m==0) ans=n-1;
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cstdlib> #include<vector> #include<map> using namespace std; const int maxn=11007; vector<int> G[maxn]; int pre[maxn],ans,root,sum,n,m,cnt[maxn]; int tarjan(int u,int fa) { int lowu=pre[u]=sum++; int l=G[u].size(); int child=0; for(int i=0;i<l;i++) { int v=G[u][i]; if(v==fa) continue; if(!pre[v]){ child++; int lowv=tarjan(v,u); lowu=min(lowv,lowu); if((u==root&&child>1)||(u!=root&&pre[u]<=lowv)){ cnt[u]++; } } else lowu=min(lowu,pre[v]); } return lowu; } int main() { int a,b; while(1){ for(int i=0;i<maxn;i++) G[i].clear(); scanf("%d%d",&n,&m); if(n==0) break; if(m==0){printf("%d\n",n-1);continue;} for(int i=0;i<m;i++) { scanf("%d%d",&a,&b); G[a].push_back(b); G[b].push_back(a); } int t=0;ans=0; memset(pre,0,sizeof(pre)); memset(cnt,0,sizeof(cnt)); for(int i=0;i<n;i++) { if(!pre[i]){ t++;root=i; sum=1; tarjan(i,-1); } ans=max(ans,cnt[i]); } printf("%d\n",t+ans); } return 0; }
相关文章推荐
- poj 2117 Electricity 求无向图中去掉一个点后最大的联通分支数 无向图有可能不联通 tarjan求割点模板
- POJ 1144 Network(求无向图中的割点)
- poj 1523(无向联通图的割点)
- POJ1144 Network (Tarjan算法求无向图的割点)
- POJ 1144 - Network 用tarjan求无向图的割点
- poj 2117 去掉割点可以分得的联通图的个数模板
- 基于DFS求无向图的割点及桥(割边)算法总结 POJ_1144题解
- poj 2117 去掉割点可以分得的联通图的个数模板
- POJ 2117 双连通求割点所连接的(连通分量数)
- POJ 1144 Network Tarjan 求无向图的割点的个数 Tarjan 模板题
- poj 2117
- poj 1144 求图的割点
- poj 1144 Network 无向图求割点
- tarjan算法--求无向图的割点和桥
- poj 2117 Electricity(求割项)
- POJ 2117(去掉割点剩下的图中最大连通块)
- Uva 315 求无向图的割点的个数
- poj 2117(统计连通块的个数)
- POJ-1734 Sightseeing trip (无向图最小环[Floyd])
- POJ 2117 Electricity