level 9
怎样求桥和割点。。
蒟蒻无力
要是给个伪代码或是pascal的程序就更好了
2012年10月28日 11点10分
1
level 3
Program Contact;
Var time,i,n,m,k:longint;
e,ne:array [1..800000] of longint;
p,st,dfn,low:array [0..800000] of longint;
ans,top:qword;
Procedure Init;
Var i,a,b:longint;
Procedure Insert(a,b:longint);
Begin
Inc(k);
e[k]:=b; ne[k]:=p[a]; p[a]:=k;
End;
Begin
Readln(n,m);
For i:=1 to m do
Begin
Readln(a,b);
Insert(a,b);
Insert(b,a);
End;
End;
Function min(a,b:longint):longint;
Begin
if a<b then exit(a) else exit(b);
End;
Procedure Tarjan(v,fa:longint);
Var i:longint;
s:qword;
Begin
Inc(time); dfn[v]:=time; low[v]:=time;
Inc(top); st[top]:=v;
i:=p[v];
While i<>0 do
Begin
If e[i]<>fa then
If dfn[e[i]]=0 then
Begin
Tarjan(e[i],v);
low[v]:=min(low[e[i]],low[v]);
If low[e[i]]>dfn[v] then
Begin
s:=0;
While true do
Begin
Inc(s);
Dec(top);
If st[top+1]=e[i] then break;
End;
ans:=ans+s*(s-1) div 2;
End;
End
else
low[v]:=min(low[v],dfn[e[i]]);
i:=ne[i];
End;
End;
Begin
Init;
For i:=1 to n+1 do
If dfn[i]=0 then
Begin
top:=0;
Tarjan(i,0);
ans:=ans+top*(top-1) div 2;
End;
writeln(ans);
End.
2012年10月29日 13点10分
9