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

有人能帮忙看看吗。。我快被WA崩溃了。。

Posted by YuGle_s_HB at 2008-07-29 16:40:23 on Problem 1144
program keypath3;
  const maxn=300;
  type
    Tmatrix=array [0..maxn,0..maxn] of longint;
    arr=array [0..maxn] of longint;
  var
    matrix:Tmatrix;
    i,j,k,n,w,v,root,net,net1:longint;
    ancestor,d,c:arr;
    cut:array [0..maxn] of boolean;
  procedure init;
    var i,j,k:longint;
    begin
      read(net1);
      while net1<>0 do
        begin
          while not eoln do
            begin
              read(net);
              matrix[net1,net]:=1;
              matrix[net,net1]:=1;
            end;
          readln;
          read(net1);
        end;
      fillchar(ancestor,sizeof(ancestor),0);
      fillchar(cut,sizeof(cut),false);
      fillchar(d,sizeof(d),0);
      fillchar(c,sizeof(c),0);
    end;
  procedure DFS(k,father,deep:longint);
    var i,tot:longint;
    begin
      c[k]:=1;
      d[k]:=deep;
      ancestor[k]:=deep;
      tot:=0;
      for i:=1to n do
        begin
          if (matrix[i,k]<>0)and(i<>father)and(c[i]=1) then
            begin
              if ancestor[k]>d[i] then
                ancestor[k]:=d[i];
            end;
          if (matrix[i,k]<>0)and(c[i]=0) then
            begin
              DFS(i,k,deep+1);
              inc(tot);
              if ancestor[k]>ancestor[i] then
                ancestor[k]:=ancestor[i];
              if ((k=root)and(tot>1))or((k<>root)and(ancestor[i]>=d[k]))then
                cut[k]:=true;
            end;
        end;
      c[k]:=2;
    end;
  procedure outit;
    var i,sum:longint;
    begin
      sum:=0;
      for i:=1to n do
        if cut[i] then inc(sum);
      if sum<>0 then writeln(sum);
    end;
  begin
    assign(input,'init\network1.in');
    reset(input);
    readln(n);
    while n<>0 do
      begin
        net:=0;
        net1:=0;
        w:=0;
        v:=0;
        i:=0;
        j:=0;
        k:=0;
        fillchar(matrix,sizeof(matrix),0);
        init;
        root:=1;
        DFS(1,0,1);
        outit;
        readln(n);
      end;
    close(input);
  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