zoukankan      html  css  js  c++  java
  • BZOJ 1015

    program bzoj1015;
    {$inline on}
    
    const maxn=400001;
    
    type node=record
        togo,next:longint;
    end;
    
    var tot,n,m,d,cnt:longint;
        father,head,q,ans:array [0..maxn] of longint;
        used,des:array [0..maxn] of boolean;
        e:array [0..maxn] of node;
    
    function find(x:longint):longint; inline;
    begin
      if father[x]=x then exit(x);
      if father[father[x]]=x then exit(father[x]);
      find:=find(father[x]);
      father[x]:=find;
    end;
    
    procedure ins(u,v:longint);  inline;
    begin
        inc(cnt);
        e[cnt].togo:=v;    e[cnt].next:=head[u]; head[u]:=cnt;
        inc(cnt);
        e[cnt].togo:=u;    e[cnt].next:=head[v]; head[v]:=cnt;
    end;
    
    procedure add(x:longint);   inline;
    var i,p,q:longint;
    begin
        i:=head[x];
        p:=find(x);
        while i<>0 do
            begin
                if used[e[i].togo] then
                    begin
                        q:=find(e[i].togo);
                        if p<>q then 
                            begin
                                father[q]:=p;
                                dec(tot);
                            end;
                    end;
                i:=e[i].next;
            end;
    end;
    
    procedure main;
    var i,x,y:longint;
    begin
        read(n,m);
            cnt:=1;
        for i:=0 to n-1 do father[i]:=i;
        for i:=1 to m do 
            begin
                read(x,y);
                ins(x,y);
            end;
        read(d);
        for i:=1 to d do
            begin
                read(q[i]);
                des[q[i]]:=true;
            end;
        for i:=0 to n-1 do
            if not(des[i]) then
            begin
                inc(tot);
                add(i);
                used[i]:=true;
            end;
        ans[d+1]:=tot;
        for i:=d downto 1 do 
            begin
                inc(tot);
                add(q[i]);
                used[q[i]]:=true;
                ans[i]:=tot;
            end;
        for i:=1 to d+1 do 
            writeln(ans[i]);
    end;
    
    begin
        main;
    end.
  • 相关阅读:
    10000个线程更新同一行数据
    CountDownLatchTest
    创建 oracle dblin
    extjs日期控件使用
    JAVA Date超强工具类,可直接取代util.Date使用
    JSP&Servlet学习手册
    JAVA 文本 TXT 操作工具类
    Leetcode 526.优美的排列
    Leetcode 525.连续数组
    Leetcode 523.连续的子数组和
  • 原文地址:https://www.cnblogs.com/logichandsome/p/4054634.html
Copyright © 2011-2022 走看看