2730 HNOI2012 礦場搭建

2022-09-06 23:03:36 字數 2533 閱讀 6887

求出割點,刪掉後求只與乙個割點相連的連通分量的個數,這就是答案。 方案數用乘法原理求就行了。 注意:只有乙個連通分量時要特判。

runid

user

problem

result

memory

time

language

code_length

submit_time

388096

lbz007

2730

accepted

228 kb

0 ms

pascal/edit

1668 b

2013-04-10 14:42:48

view code

[toggle title="code"] [pascal] var m,n,du,ttt,tot,u,v,i,j,color,ee:longint; c,num,ll,size,pre,head,next,e:array[1..1000]of longint; vv,cut:array[1..1000]of boolean; an,ans:int64; function min(aa,bb:longint):longint; begin

if aathen exit(aa) else exit(bb); end; procedure dfs(u:longint); var j:longint; begin c[u]:=color; inc(size[color]); vv[u]:=true; j:=head[u]; while j<>0

dobegin

ifnot vv[e[j]] then

begin

if cut[e[j]] then

begin inc(num[color]); vv[e[j]]:=true; end

else dfs(e[j]); end; j:=next[j]; end; end; procedure dfsgd(u:longint); var j:longint; begin inc(tot);ll[u]:=tot;pre[u]:=tot; j:=head[u]; while j<>0

dobegin

ifnot vv[j] then

begin vv[j]:=true; vv[(j+1) xor 1-1]:=true; if pre[e[j]]=0

then

begin dfsgd(e[j]); ll[u]:=min(ll[u],ll[e[j]]); if u=1

then inc(du); if ll[e[j]]>=pre[u] then cut[u]:=true; end

else ll[u]:=min(ll[u],pre[e[j]]); end; j:=next[j]; end; end; procedure add(u,v:longint); begin inc(ee); e[ee]:=v;next[ee]:=head[u];head[u]:=ee; end; procedure init; begin inc(ttt);tot:=0; fillchar(pre,sizeof(pre),0); fillchar(ll,sizeof(ll),0); fillchar(head,sizeof(head),0); color:=0;n:=0;ans:=0;du:=0; fillchar(size,sizeof(size),0); fillchar(num,sizeof(num),0); fillchar(c,sizeof(c),0); fillchar(vv,sizeof(vv),false); fillchar(cut,sizeof(cut),false); end; begin readln(m); while m<>0

dobegin init; for i:=1

to m do

begin readln(u,v); add(u,v);add(v,u); if

not vv[u] then inc(n); if

not vv[v] then inc(n); vv[u]:=true;vv[v]:=true; end; fillchar(vv,sizeof(vv),false); dfsgd(1); if du>1

then cut[1]:=true else cut[1]:=false; for i:=1

to n do

if (not cut[i])and(c[i]=0) then

begin inc(color); size[color]:=0; fillchar(vv,sizeof(vv),false); dfs(i); end; an:=1; if color=1

then

begin ans:=2; an:=(n-1)*n div

2; end

else

for i:=1

to color do

if num[i]<=1

then

begin inc(ans); an:=an*size[i]; end; writeln('

case

',ttt,'

: ',ans,'

',an); readln(m); end; end. [/pascal] [/toggle]

bzoj 2730 HNOI2012 礦場搭建

description 煤礦工地可以看成是由隧道連線挖煤點組成的無向圖。為安全起見,希望在工地發生事故時所有挖煤點的工人都能有一條出路逃到救援出口處。於是礦主決定在某些挖煤點設立救援出口,使得無論哪乙個挖煤點坍塌之後,其他挖煤點的工人都有一條道路通向救援出口。請寫乙個程式,用來計算至少需要設定幾個救...

BZOJ 2730 HNOI2012 礦場搭建

time limit 10 sec memory limit 128 mb submit 2340 solved 1086 submit status discuss 煤礦工地可以看成是由隧道連線挖煤點組成的無向圖。為安全起見,希望在工地發生事故時所有挖煤點的工人都能有一條出路逃到救援出口處。於是礦...

BZOJ2730 HNOI2012 礦場搭建

題解 一道水題交了5次才過 只需考慮刪去的點是割點的情況。刪去所有割點,形成若干聯通塊,假如圖中只有乙個聯通塊,則需設定兩個出口。若乙個聯通塊可以到達兩個割點,則該聯通塊內不必設定出口,否則必須設定出口。方案數利用乘法原理計算即可。一定要注意細節。co de cod e include includ...