• toj1026 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



  • 相关阅读:
    非常不错的学习网站——技术胖
    Vue中使用mescroll.js实现下拉刷新
    2020.10.07【NOIP提高A组】模拟
    2020.10.06【NOIP提高A组】模拟 总结
    2020.09.19【NOIP提高A组】模拟
    2020.09.12【NOIP提高A组】模拟
    GMOJ 4417. 【HNOI2016模拟4.1】神奇的字符串 题解
    上下界网络流学习笔记
    GMOJ 3571. 【GDKOI2014】内存分配 题解
    [模板]人工栈
  • 原文地址:https://www.cnblogs.com/zyx-crying/p/9319671.html
Copyright © 2020-2023  润新知