Advertisement
trankhanh47

bridge&cut_edge

May 20th, 2019
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.12 KB | None | 0 0
  1. // bridge + cut_edge
  2. uses crt;
  3.  
  4. const   fi='test.inp';
  5.         fo='test.out';
  6.  
  7. var     a:array[1..10000,1..10000] of boolean;
  8.         n,m,count,cau,khop:longint;
  9.         numbering,low,nc: array[1..10000] of integer;
  10.         mark:array[1..1000] of boolean;
  11.  
  12. procedure init;
  13. begin
  14.         fillchar(a,sizeof(a),false);
  15.         fillchar(numbering,sizeof(numbering),0);
  16.         fillchar(nc,sizeof(nc),0);
  17.         count:=0; cau:=0; khop:=0;
  18. end;
  19.  
  20. procedure inp;
  21. var i,u,v:integer;
  22. begin
  23.         readln(n,m);
  24.         init;
  25.         for i:=1 to  m do
  26.                 begin
  27.                 readln(u,v);
  28.                 a[u,v]:=true;
  29.                 a[v,u]:=true;
  30.                 end;
  31. end;
  32.  
  33. function min(x,y:integer):integer;
  34. begin
  35.         if x<y then exit(x) else exit(y);
  36. end;
  37.  
  38. procedure visit(u:integer);
  39. var v:integer;
  40. begin
  41.         inc(count);
  42.         numbering[u]:=count;
  43.         low[u]:=n+1;
  44.         mark[u]:=false;
  45.         for v:=1 to n do
  46.                 if a[u,v] then
  47.                         begin
  48.                         a[v,u]:=false;
  49.                         if numbering[v]=0 then
  50.                                 begin
  51.                                 inc(nc[u]);
  52.                                 visit(v);
  53.                                 mark[u]:=mark[u] or (low[v]>=numbering[u]);
  54.                                 if low[v]>numbering[u] then inc(cau);
  55.                                 low[u]:=min(low[u],low[v]);
  56.                                 end
  57.                         else low[u]:=min(low[u],numbering[v]);
  58.                         end;
  59. end;
  60.  
  61. procedure work;
  62. var i:integer;
  63. begin
  64.         for i:=1 to n do
  65.                 if numbering[i]=0 then
  66.                 begin
  67.                 visit(i);
  68.                 if nc[i]<2 then mark[i]:=false; //dinh i la goc cay DFS
  69.                  //if mark[i] then writeln(i);
  70.                 end;
  71.         for i:=1 to n do
  72.         if mark[i] then inc(khop);
  73.         Write(khop,' ', cau);
  74. end;
  75.  
  76. begin
  77.         assign(input,fi);reset(input);
  78.         assign(output,fo);rewrite(output);
  79.         inp;
  80.         work;
  81.         close(input); close(output);
  82. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement