{ 用邻接矩阵表示图 }
adj_matrix=array [1..MaxSize,1..MaxSize] of integer;
procedure fundament;
const infile='DFS.in';
outfile='DFS.out';
var
probN:integer;
fin,fout:text;
n:integer;
G:adj_matrix;
function init:boolean;
var i,j,k,m:integer;
begin
init:=false;
if eof(fin) then exit;
//insert your codes
readln(fin,n,m);
if n=0 then exit;
inc(probN);
fillchar(G,sizeof(g),0);
for k:=1 to m do
begin
readln(fin,i,j);
G[i,j]:=1;
end;
//end your codes here
init:=true;
end;
============================================}
procedure DFS(var G:adj_matrix;size:integer);
const
white=0;
gray=-1;
black=1;
var
EdgeType:adj_matrix;
d,f,c,p,b,l:array[1..MaxSize] of integer;
u,time:integer;
procedure DFS_visit(u:integer);
var
v:integer;
begin
c[u]:=gray;
inc(time);
d[u]:=time;
l[u]:=time;
for v:=1 to size do
if G[u,v]>0 then {G[u,v]>0表示边(u,v)存在且未被访问,当边(u,v)不存在时G[u,v]=0}
case c[v] of
white: begin
{!!!} {G[u,v]:=-G[u,v]; {设置(u,v)暂时不可访问的标志,对于有向图,请把此行删去}
EdgeType[u,v]:=1; {(u,v)为树枝边}
inc(b[u]); {深度优先树中顶点u的度数加1}
p[v]:=u; {深度优先树中顶点v的父亲是u}
DFS_visit(v); {深度优先搜索顶点v}
if l[v]<l[u] then l[u]:=l[v]; {u的儿子v的关联边全部被访问时,l[u]=min(l[u],l[v])}
{!!!} {G[u,v]:=-G[u,v]; {恢复(u,v)可访问,对于有向图,请把此行删去}
end;
gray: begin
EdgeType[u,v]:=2; {(u,v)为反向边}
if d[v]<l[u] then l[u]:=d[v]; {访问反向边(u,v)时,l[u]:=min(l[u],d[v])}
end;
black: begin
if d[v]>d[u] then EdgeType[u,v]:=3 {(u,v)为正向边}
else EdgeType[u,v]:=4; {(u,v)为交叉边}
end;
end; {end of case}
c[u]:=black;
inc(time);
f[u]:=time;
end;
procedure Print;
var
i,j:integer;
begin
writeln(fout,'Edge Type:');
for i:=1 to size do
for j:=1 to size do
case EdgeType[i,j] of
1: writeln(fout,i,' ',j,' ','树枝边');
2: writeln(fout,i,' ',j,' ','反向边');
3: writeln(fout,i,' ',j,' ','正向边');
4: writeln(fout,i,' ',j,' ','交叉边');
end;
writeln(fout,'d:');
for i:=1 to size do writeln(fout,d[i]);
writeln(fout,'f:');
for i:=1 to size do writeln(fout,f[i]);
writeln(fout,'p:');
for i:=1 to size do writeln(fout,p[i]);
writeln(fout,'b:');
for i:=1 to size do writeln(fout,b[i]);
writeln(fout,'l:');
for i:=1 to size do writeln(fout,l[i]);
end;
begin
fillchar(c,sizeof(c),white);
fillchar(p,sizeof(p),0);
fillchar(b,sizeof(b),0);
time:=0;
for u:=1 to size do
if c[u]=white then DFS_visit(u);
Print;
end;
procedure main;
var i,j,k:integer;
begin
//insert your codes
writeln(fout,'Case ',probN);
DFS(G,n);
//end your codes here
end;
begin
assign(fin,infile); reset(fin);
assign(fout,outfile); rewrite(fout);
probN:=0;
while init do main;
close(fin); close(fout);
end;