码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ 1015

时间:2014-10-27 19:06:29      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   ar   for   sp   div   

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.

 

BZOJ 1015

标签:des   style   blog   io   color   ar   for   sp   div   

原文地址:http://www.cnblogs.com/logichandsome/p/4054634.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!