Electricity_toj2299_割点

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 Specification

The input consists of several instances.
The first line of each instance contains two integers 1 ≤ P ≤ 10 000 and 0 ≤ C ≤ 20 000 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 Specification

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. 先DFS求出图的块数num
  2. 求割点记录
  3. 找到最大的割点数量为max,num-max-1
  4. ps:数组开小会爆Restricted Function,切记

源代码/pas:

type
  edge=record
    y,next:longint;
  end;
var
  e:array[0..40000]of edge;
  ans,dfn,low,ls:array[0..10000]of longint;
  n,m,maxE,t:longint;
function min(x,y:longint):longint;
begin
  min:=x;
  if y<x then
  min:=y;
end;
procedure add(x,y:longint);
begin
  inc(maxE);
  e[maxE].y:=y;
  e[maxE].next:=ls[x];
  ls[x]:=maxE;
end;
procedure tarjan(x:longint);
var
  i:longint;
begin
  inc(t);
  dfn[x]:=t;
  low[x]:=t;
  i:=ls[x];
  while i>0 do
  with e[i] do
  begin
    if dfn[y]=0 then
    begin
      tarjan(y);
      low[x]:=min(low[x],low[y]);
      if low[y]>=dfn[x] then inc(ans[x]);
    end
    else
    low[x]:=min(low[x],dfn[y]);
    i:=next;
  end;
end;
procedure main;
var
  i,num,g:longint;
begin
  fillchar(ans,sizeof(ans),0);
  fillchar(dfn,sizeof(dfn),0);
  fillchar(low,sizeof(low),0);
  t:=0;
  g:=0;
  for i:=1 to n do
  if dfn[i]=0 then
  begin
    inc(g);
    tarjan(i);
  end;
  num:=0;
  for i:=1 to n do
  if g+ans[i]>num then num:=g+ans[i];
  writeln(num-1);
end;
procedure init;
var
  i,x,y:longint;
begin
  fillchar(ls,sizeof(ls),0);
  maxE:=0;
  for i:=1 to m do
  begin
    readln(x,y);
    add(x+1,y+1);
    add(y+1,x+1);
  end;
end;
begin
  readln(n,m);
  while n+m>0 do
  begin
    init;
    main;
    readln(n,m);
  end;
end.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SELECT settlement_date settlementDate, unique_identification uniqueIdentification, batch_id batchId, participant_id participantId, participant_name participantName, participant_type participantType, participant_code participantCode, administrative, credit_code creditCode, solidify_type solidifyType, involved_power_grid involvedPowerGrid, nature_enterprise natureEnterprise, phone, company_phone companyPhone, bank, account_name accountName, account, status, enter_time enterTime, left_time leftTime, is_market isMarket, participant_area_code participantAreaCode, trading_industry_type tradingIndustryType, enterprise_type enterpriseType, market_id marketId, mkt_account_number mktAccountNumber, mkt_account_name mktAccountName, gdj, city_burean cityBurean, ele_address eleAddress, account_voltage accountVoltage, electricity_type electricityType, file_update_time fileUpdateTime, industry_type industryType, hi_energy_consumption hiEnergyConsumption, installed_capacity installedCapacity, run_cap runCap, temporary_electric_flag temporaryElectricFlag, account_area_code accountAreaCode, account_status accountStatus, account_runstatus accountRunstatus, meter_id meterId, meter_code meterCode, meter_name meterName, meter_credit_code meterCreditCode, sbs_account_number sbsAccountNumber, sbs_account_name sbsAccountName, meter_area_code meterAreaCode, meter_status meterStatus, meter_runstatus meterRunstatus, meter_voltage meterVoltage, meter_electricity_type meterElectricityType, push_status pushStatus FROM mm_user_participant_day_hn where settlement_date Between '2023-04-01' and '2023-04-31' AND (solidify_type = '02' or solidify_type = '03');帮我优化一下性能
06-03

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值