• 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.
  • 相关阅读:
    单例模式
    分析GC日志
    JVM运行时参数
    JVM监控及诊断工具-GUI篇
    JVM监控及诊断工具-命令行篇
    性能监控与调优(概述篇)
    再谈类的加载器
    类的加载过程(类的生命周期)详解
    字节码指令集
    class文件结构
  • 原文地址:https://www.cnblogs.com/logichandsome/p/4054634.html
Copyright © 2020-2023  润新知