比赛 20120711 评测结果 AAAAAAWAAAAAAAAAA
题目名称 Redundant Paths 最终得分 94
用户昵称 SnowDancer 运行时间 0.014 s
代码语言 Pascal 内存使用 0.51 MiB
提交时间 2012-07-11 11:44:40
显示代码纯文本
program rpathsa;
type
  point=^node;
  node=record x:longint;next:point; end;
var
  n,i,j,k,l,index,tot,tops,m:longint;
  dfn,low,stack,fa,ind:array[1..5000] of longint;
  nodes:array[1..30000] of node;
  h:array[1..5000] of point;
  top,p:point;
procedure insertE(u,v:longint);
  begin
    top^.x:=v;top^.next:=h[u];
    h[u]:=top; inc(top);
  end;
procedure CalCutEdge(v,pre:longint);
  var
    p:point;
    u:longint;
  begin
    inc(index); dfn[v]:=index; low[v]:=index;
    inc(tops);stack[tops]:=v;
    p:=h[v];
    while p<>nil do begin
      u:=p^.x;
      if u<>pre then
        if dfn[u]=0 then begin
          CalCutEdge(u,v);
          if low[u]<low[v] then
            low[v]:=low[u];
          if low[u]>dfn[v] then
            repeat
              k:=stack[tops];
              fa[k]:=u;dec(tops);
            until k=u;
        end else
          if dfn[u]<low[v] then
            low[v]:=dfn[u];
      p:=p^.next;
    end;
  end;
begin
  assign(input,'rpathsa.in');reset(input);
  assign(output,'rpathsa.out');rewrite(output);
  readln(n,m);  top:=@nodes[1];
  for k:=1 to m do begin
    readln(i,j);
    insertE(i,j);
    insertE(j,i);
  end;
  for i:=1 to n do
    if dfn[i]=0 then begin
      CalCutEdge(i,0);
      while tops>0 do begin
        fa[stack[tops]]:=i;
        dec(tops);
      end;
    end;
  for i:=1 to n do begin
    p:=h[i];
    while p<>nil do begin
      if fa[i]<>fa[p^.x] then
        inc(ind[fa[p^.x]]);
      p:=p^.next;
    end;
  end;
  for i:=1 to n do
    if ind[i]=1 then
      inc(tot);
  writeln((tot+1)>>1);
  close(input);close(output);
end.