zoukankan      html  css  js  c++  java
  • poj1144 Network 双连通分量

    题意/Description:

        A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N . No two places have the same number. The lines are bidirectional and always connect together two places and in each place the lines end in a telephone exchange. There is one telephone exchange in each place. From each place it is possible to reach through lines every other place, however it need not be a direct connection, it can go through several exchanges. From time to time the power supply fails at a place and then the exchange does not operate. The officials from TLC realized that in such a case it can happen that besides the fact that the place with the failure is unreachable, this can also cause that some other places cannot connect to each other. In such a case we will say the place (where the failure occured) is critical. Now the officials are trying to write a program for finding the number of all such critical places. Help them.

     

    读入/Input

            The input file consists of several blocks of lines. Each block describes one network. In the first line of each block there is the number of places N < 100. Each of the next at most N lines contains the number of a place followed by the numbers of some places to which there is a direct line from this place. These at most N lines completely describe the network, i.e., each direct connection of two places in the network is contained at least in one row. All numbers in one line are separated by one space. Each block ends with a line containing just 0. The last block has only one line with N = 0;

     

    输出/Output

            The output contains for each block except the last in the input file one line containing the number of critical places.

     

    题解/solution

            改一下输入(输入十分神奇),水水的连通图。详情见:

    http://www.cnblogs.com/en-heng/p/4002658.html

     

    代码/Code

    type
      arr=record
        y,next,op:longint;
        f:boolean;
      end;
    var
      dfn,low,ls:array [0..101] of longint;
      tu:array [0..1001] of arr;
      ans:array [0..101] of boolean;
      n,m,tot,p,cnt:longint;
    procedure add(o,p:longint);
    begin
      inc(tot);
      with tu[tot] do
        begin
          y:=p; op:=tot+1;
          next:=ls[o];
          ls[o]:=tot;
        end;
      inc(tot);
      with tu[tot] do
        begin
          y:=o; op:=tot-1;
          next:=ls[p];
          ls[p]:=tot;
        end;
    end;
    
    function min(o,p:longint):longint;
    begin
      if o<p then exit(o);
      exit(p);
    end;
    
    procedure tarjan(x:longint);
    var
      t:longint;
    begin
      inc(p);
      dfn[x]:=p; low[x]:=p;
      t:=ls[x];
      while t>0 do
        with tu[t] do
          begin
            if not f then
              begin
                f:=true;
                tu[op].f:=true;
                if dfn[y]=0 then
                  begin
                    if x=1 then inc(cnt);
                    tarjan(y);
                    low[x]:=min(low[x],low[y]);
                    if low[y]>=dfn[x] then ans[x]:=true;
                  end else
                  low[x]:=min(low[x],dfn[y]);
              end;
            t:=next;
          end;
    end;
    
    procedure print;
    var
      i,sum:longint;
    begin
      if cnt>=2 then ans[1]:=true
                else ans[1]:=false;
      sum:=0;
      for i:=1 to n do
        if ans[i] then inc(sum);
      writeln(sum);
    end;
    
    procedure init;
    var
      i,x,y:longint;
    begin
      readln(n);
      while n<>0 do
        begin
          cnt:=0; tot:=0;
          fillchar(dfn,sizeof(dfn),0);
          fillchar(low,sizeof(low),0);
          fillchar(tu,sizeof(tu),0);
          fillchar(ls,sizeof(ls),0);
          fillchar(ans,sizeof(ans),0);
          read(x);
          while x<>0 do
            begin
              while not eoln do
                begin
                  read(y);
                  add(x,y);
                end;
              read(x);
            end;
          tarjan(1);
          print;
          readln(n);
        end;
    end;
    
    begin
      init;
    end.



  • 相关阅读:
    第一册:lesson forty five。
    第一册:lesson forty three。
    马化腾2015港大演讲。
    Swing实现文件选择(目录选择)附导出
    SVN强制注释
    Websphere内存溢出的日志
    sql server2008 搭建链接服务器成功后查询时报Cannot obtain the schema rowset "DBSCHEMA_TABLES_INFO" for OLE DB provider "SQLNCLI10" for linked server "XXXXX". 的解决方法
    UML图例
    jSP的3种方式实现radio ,checkBox,select的默认选择值。
    通过js子页面回写父页面,改变父页面控件的值
  • 原文地址:https://www.cnblogs.com/zyx-crying/p/9319674.html
Copyright © 2011-2022 走看看