BZOJ 1015

时间:2022-09-21 04:06:44
program bzoj1015;
{$inline on} const maxn=; type node=record
togo,next:longint;
end; var tot,n,m,d,cnt:longint;
father,head,q,ans:array [..maxn] of longint;
used,des:array [..maxn] of boolean;
e:array [..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<> 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:=;
for i:= to n- do father[i]:=i;
for i:= to m do
begin
read(x,y);
ins(x,y);
end;
read(d);
for i:= to d do
begin
read(q[i]);
des[q[i]]:=true;
end;
for i:= to n- do
if not(des[i]) then
begin
inc(tot);
add(i);
used[i]:=true;
end;
ans[d+]:=tot;
for i:=d downto do
begin
inc(tot);
add(q[i]);
used[q[i]]:=true;
ans[i]:=tot;
end;
for i:= to d+ do
writeln(ans[i]);
end; begin
main;
end.