• 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.
  • 相关阅读:
    visual sudio开发工具使用小技巧
    JS去除右边的逗号
    下拉标题
    sp_addextendedproperty
    触发器的使用
    缺失一个正数
    组合总和 去重
    拖动 Drag
    n皇后问题
    括号生成
  • 原文地址:https://www.cnblogs.com/logichandsome/p/4054634.html
Copyright © 2020-2023  润新知