zoukankan      html  css  js  c++  java
  • 外星人入侵 (Standard IO)

    Description

    外星人入侵地球。可怕的吃人外星人正在全国各地依次序建立它们的基地。

    全国共有N(1≤ N ≤10,000)座城市,城市编号1~N。城市之间有M(0≤ M ≤100,000)条双向道路相连。外星人计划建立A(0≤A≤N)个基地。

    你只有在距离当前所有外星人基地至少K(1≤K≤100)单位长度的城市才能得到安全。

    所以你必须赶快写一个程序决定走到哪里去。

    Input

    第1行:4个整数N, M, A, K

    接下来M行,每行3个整数T1, T2(1≤T1

    const
      maxE=100001;
      maxV=400001;
    
    type
      arr=record
        x,y,w,next:int64;
      end;
    
    var
      n,m,nm,nn,mm,ans:longint;
      a:array [0..maxV] of arr;
      ls:array [0..maxE] of longint;
      list,d,v:array [0..maxE] of int64;
      f:array [0..10001] of boolean;
    procedure spfa(st:longint);
    var
      i,k,h,t:longint;
    begin
      fillchar(d,sizeof(d),63);
      fillchar(v,sizeof(v),0);
      fillchar(list,sizeof(list),0);
      h:=0; t:=1;
      v[st]:=1; list[1]:=st; d[st]:=0;
      repeat
        h:=h+1;
        i:=ls[list[h]];
        while i<>0 do
          begin
            with a[i] do
              begin
                if d[x]+w<d[y] then
                  begin
                    d[y]:=d[x]+w;
                    if v[y]=0 then
                      begin
                        t:=t+1;
                        list[t]:=y;
                        v[y]:=1;
                      end;
                  end;
                i:=next;
              end;
          end;
        v[list[h]]:=0;
      until h=t;
    end;
    
    procedure init;
    var
      i:longint;
    begin
      readln(n,m,nn,mm);
      for i:=1 to m do
        begin
          with a[i] do
            begin
              readln(x,y,w);
              next:=ls[x];
              ls[x]:=i;
            end;
          with a[m+i] do
            begin
              x:=a[i].y; y:=a[i].x;
              w:=a[i].w;
              next:=ls[x];
              ls[x]:=i+m;
            end;
        end;
      m:=m*2;
    end;
    
    procedure print;
    var
      i,j,t:longint;
    begin
      fillchar(f,sizeof(f),true);
      for i:=1 to nn do
        begin
          readln(t);
          spfa(t);
          ans:=0;
          for j:=1 to n do
            if (d[j]>=mm) and f[j] then inc(ans)
                                   else f[j]:=false;
          writeln(ans);
        end;
    end;
    
    begin
      init;
      print;
    end.
    
    
  • 相关阅读:
    zoj 3279 线段树 OR 树状数组
    fzu 1962 树状数组 OR 线段树
    hdu 5057 块状链表
    hdu3487 Play with Chain
    bzoj 1588营业额统计(HNOI 2002)
    poj2823 Sliding Window
    poj2828 Buy Tickets
    poj2395 Out of Hay
    poj3667 Hotel
    poj1703 Lost Cows
  • 原文地址:https://www.cnblogs.com/zyx-crying/p/9319594.html
Copyright © 2011-2022 走看看