Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // bridge + cut_edge
- uses crt;
- const fi='test.inp';
- fo='test.out';
- var a:array[1..10000,1..10000] of boolean;
- n,m,count,cau,khop:longint;
- numbering,low,nc: array[1..10000] of integer;
- mark:array[1..1000] of boolean;
- procedure init;
- begin
- fillchar(a,sizeof(a),false);
- fillchar(numbering,sizeof(numbering),0);
- fillchar(nc,sizeof(nc),0);
- count:=0; cau:=0; khop:=0;
- end;
- procedure inp;
- var i,u,v:integer;
- begin
- readln(n,m);
- init;
- for i:=1 to m do
- begin
- readln(u,v);
- a[u,v]:=true;
- a[v,u]:=true;
- end;
- end;
- function min(x,y:integer):integer;
- begin
- if x<y then exit(x) else exit(y);
- end;
- procedure visit(u:integer);
- var v:integer;
- begin
- inc(count);
- numbering[u]:=count;
- low[u]:=n+1;
- mark[u]:=false;
- for v:=1 to n do
- if a[u,v] then
- begin
- a[v,u]:=false;
- if numbering[v]=0 then
- begin
- inc(nc[u]);
- visit(v);
- mark[u]:=mark[u] or (low[v]>=numbering[u]);
- if low[v]>numbering[u] then inc(cau);
- low[u]:=min(low[u],low[v]);
- end
- else low[u]:=min(low[u],numbering[v]);
- end;
- end;
- procedure work;
- var i:integer;
- begin
- for i:=1 to n do
- if numbering[i]=0 then
- begin
- visit(i);
- if nc[i]<2 then mark[i]:=false; //dinh i la goc cay DFS
- //if mark[i] then writeln(i);
- end;
- for i:=1 to n do
- if mark[i] then inc(khop);
- Write(khop,' ', cau);
- end;
- begin
- assign(input,fi);reset(input);
- assign(output,fo);rewrite(output);
- inp;
- work;
- close(input); close(output);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement