zoukankan      html  css  js  c++  java
  • POJ 2117 Electricity

    Electricity

    Time Limit: 5000ms
    Memory Limit: 65536KB
    This problem will be judged on PKU. Original ID: 2117
    64-bit integer IO format: %lld      Java class name: Main
     
    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

     
    解题:求某个割点的割边数以及连通块数。
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <climits>
     7 #include <vector>
     8 #include <queue>
     9 #include <cstdlib>
    10 #include <string>
    11 #include <set>
    12 #include <stack>
    13 #define LL long long
    14 #define pii pair<int,int>
    15 #define INF 0x3f3f3f3f
    16 using namespace std;
    17 const int maxn = 10100;
    18 int p,c;
    19 int dfn[maxn],low[maxn],cut[maxn],vis[maxn],cnt;
    20 vector<int>g[maxn];
    21 void tarjan(int u,int fa){
    22     dfn[u] = low[u] = ++cnt;
    23     int son = 0;
    24     vis[u] = 1;
    25     for(int i = 0; i < g[u].size(); i++){
    26         if(!vis[g[u][i]]){
    27             tarjan(g[u][i],u);
    28             son++;
    29             low[u] = min(low[u],low[g[u][i]]);
    30             if(fa == -1 && son > 1 || fa != -1 && dfn[u] <= low[g[u][i]]) cut[u]++;
    31         }else if(g[u][i] != fa && vis[g[u][i]] == 1) low[u] = min(low[u],dfn[g[u][i]]);
    32     }
    33     vis[u] = 2;
    34 }
    35 int main() {
    36     int i,u,v,ans,sum;
    37     while(scanf("%d %d",&p,&c),p||c){
    38         if(!c){printf("%d
    ",p-1);continue;}
    39         for(i = 0; i <= p; i++){
    40             g[i].clear();
    41             vis[i] = 0;
    42             dfn[i] = 0;
    43             cut[i] = 0;
    44         }
    45         for(i = 0; i < c; i++){
    46             scanf("%d %d",&u,&v);
    47             g[u].push_back(v);
    48             g[v].push_back(u);
    49         }
    50         ans = sum = cnt = 0;
    51         for(i = 0; i < p; i++){
    52             if(!vis[i]){tarjan(i,-1);sum++;}
    53             if(cut[i] > ans) {ans = cut[i];}
    54         }
    55         printf("%d
    ",ans+sum);
    56     }
    57     return 0;
    58 }
    View Code
  • 相关阅读:
    按enter执行click或者搜索问题
    网络搜集-获取文件大小
    js获取文件大小
    JQuery UI Autocomplete与jquery.autocomplete.js
    如何在 IIS 中设置 HTTPS 服务
    什么是大数据(二)—涉及行业
    什么是大数据(一)
    未能加载文件或程序集“ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=n
    安装数据库出现错误vc_red.msi找不到
    网页兼容性注意事项
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/3936903.html
Copyright © 2011-2022 走看看