Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

反正蒟蒻考虑重边偶然过了

Posted by Hoblovski at 2014-04-22 00:04:58 on Problem 3177
付DFS代码(不考虑重边版本参见LRJ黑书),用静态邻接表写的 p 和 p xor 1 是同一条边只是方向不同

由于有重边
所以判断回父亲边的时候不能用边终点是否是父亲来判断,而是直接判断边.

procedure dfs(u,p,d:longint);
var t1,cnt:longint;
begin
v[u]:=true; cnt:=0; dep[u]:=d; low[u]:=d;
t1:=g[u]; while t1<>0 do begin
        if not v[mem[t1].n] then begin
                dfs(mem[t1].n,t1,d+1); inc(cnt);
                low[u]:=min(low[u],low[mem[t1].n]);
        end else if (t1<>p)and(t1<>p xor 1) then low[u]:=min(low[u],dep[mem[t1].n]);
        //if ((u=root)and(cnt>1))or((u<>root)and(low[mem[t1].n]>=dep[u])) then cut[u]:=true;
        if (low[mem[t1].n]>dep[u]) then begin mem[t1].b:=true; mem[t1 xor 1].b:=true; end;
        t1:=mem[t1].next;
end;
end;

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator