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

poj2117pascal

Posted by yu179121 at 2015-03-22 14:34:52 on Problem 2117
type
  rec=record
    y,nx:longint;
  end;
var
  n,m,i,u,v,nx,ans,d,t,rs,tt:longint;
  q:array[-1..500050] of rec;
  vs:array[-1..10050] of 0..2;
  low,dfn,sws,h:array[-1..10050] of longint;
function min(x,y:longint):longint;
begin
  if x<y then exit(x)
  else exit(y);
end;
procedure dfs(u,fa,dp:longint);
var
  i,v,sm:longint;
begin
  i:=h[u];sm:=0;low[u]:=dp;dfn[u]:=dp;vs[u]:=1;
  while i>0 do
    begin
      v:=q[i].y;
      if (vs[v]=1) and (v<>fa) then low[u]:=min(low[u],dfn[v]);
      if vs[v]=0 then
        begin
          inc(sm);
          dfs(v,u,dp+1);
          low[u]:=min(low[u],low[v]);
          if ((u=d) and (sm>1)) or ((u<>d) and (low[v]>=dfn[u])) then inc(sws[u]);
        end;
      i:=q[i].nx;
    end;
  vs[u]:=2;
end;
begin
  while not eof do
    begin
      readln(n,m);
      if (n=0) and (m=0) then break;
      dec(n);
      fillchar(vs,sizeof(vs),0);
      fillchar(sws,sizeof(sws),0);
      fillchar(dfn,sizeof(dfn),0);
      fillchar(h,sizeof(h),255);
      rs:=0;
      for i:=1 to m do
        begin
          readln(u,v);
          inc(rs);q[rs].y:=v;q[rs].nx:=h[u];h[u]:=rs;
          inc(rs);q[rs].y:=u;q[rs].nx:=h[v];h[v]:=rs;
        end;
      tt:=0;
      for i:=0 to n do
        if vs[i]=0 then
          begin
            d:=i;
            inc(tt);dfs(i,-1,1);
          end;
      ans:=0;
      for i:=0 to n do
        if sws[i]>ans then ans:=sws[i];
      if tt>n then writeln(n)
      else writeln(ans+tt);
    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