Cubeneo @ 2019-11-10 16:48:21
思路都是对的,就是改拆为建反起搞。邻接表存边。并查集判通。请问是不是我对于cnt的操作有问题?检查了好久没搞定,网上查 并查集判通 思路和我一样的
(但是别人cpp版我看着不习惯)。我改了两天了QAQ
Uses math ;
Const maxm = 200000+3 ; maxn = 2*maxm+3 ; maxk = maxn+3 ;
type edge = record
go : Longint ; //end .
next : Longint ; //next edge .
end ;
Var edges : Array [0..maxm*2] of edge ; //edges' list .
Var G : Array [0..maxn] of Longint ; //Graph .
var E : Array [0..maxn] of Longint ; //Find-Union sets .
Var yet : Array [0..maxn] of boolean ; //Did you be destoried?
Var que, ans : Array [0..maxk] of Longint ; //Questions, and Answers.
Var abc : Array [0..maxn] of Boolean ;
var cnt, m, n, k : Longint ;
Function head(a:Longint):Longint ;
Begin
if yet[E[a]]=False then exit(0) ;
if (E[a] = a) //or (yet[E[a]]=False)
then exit(a)
else begin E[a] := Head(E[a]); exit(E[a]) End;
End;
Function Find(a, b : Longint):Boolean ; Begin exit(Head(a)=Head(b)) End;
Procedure Union(a, b : Longint) ;
Begin
if not(Find(a,b)) then Dec(cnt) ;
E[Head(a)] := Head(b) ;
End;
//Common Find-Union sets' operations.
Procedure getData ;
Var i, j, a, b : Longint ;
Begin
Readln(n, m);
For i := 1 to m do
Begin
Readln(a, b);
edges[i].go := b+1 ;
edges[i].next := G[a+1] ;
G[a+1] := i ;
edges[m+i].go := a+1 ;
edges[m+i].next := G[b+1] ;
G[b+1] := m+i ;
End;
Readln(k);
FillChar(yet,sizeof(Boolean)*n,True); //Yet.
For i := 1 to k do
Begin
Readln(a);
que[i] := a+1 ;
yet[que[i]] := False ; //I did.
End ;
For i := 0 to n do Begin E[i] := i ; End;
For i := 1 to n do
if yet[i]
then Begin
b := G[i] ;
while b>0 do
Begin
if yet[edges[b].go] then Union(i,edges[b].go);
b := edges[b].next ;
End;
End;
cnt := 0 ;
FillChar(abc,sizeof(Boolean)*n,False);
For i := 1 to n do
Begin
if (yet[i]) and (abc[Head(i)]=False)
then Begin
Inc(cnt);
abc[Head(i)] := True ;
End;
End;
End;
Procedure workOut ;
Var i, j, a, b : Longint ;
Var pt : Longint = 0 ;
Begin
Ans[0] := cnt ;
For i := k downto 1 do
Begin
inc(pt);
a := que[i] ;
Inc(cnt);
yet[a] := True ;
b := G[a] ;
while b > 0 do
Begin
if yet[edges[b].go] then Union(a,edges[b].go);
b := edges[b].next;
End;
Ans[pt] := cnt ;
End;
For i := k downto 0 do
writeln(Ans[i]);
End;
Begin
getData ;
workOut ;
End.
码风清奇,问题不大√
by CreeperLordVader @ 2019-11-10 16:49:25
为什么不用C++呢
by 已注销HeBhs37KwrDer @ 2019-11-10 16:51:34
为什么不用C++呢
by 0nullptr @ 2019-11-10 16:52:37
为什么不用C++呢
by Cubeneo @ 2019-11-10 16:53:52
因为我帅
呸呸呸
话说有人能帮帮忙么
试图召唤LG隐藏P党dalao
by Ynoi @ 2019-11-10 16:55:16
P党!
好怀念啊~初一到时候我还是P党,那时候P党到处都是,现在(包括我自己)都是C++了
by Cubeneo @ 2019-11-10 16:57:32
别光顾着发表评论啊
救救掉蓝蒟蒻吧
by Cubeneo @ 2019-11-10 17:06:08
dd别沉
by HeinzGuderian @ 2019-11-10 17:16:54
为什么不用C++呢
by kkkstra @ 2019-11-21 08:56:37
为什么不用C++呢
by _SAR_ @ 2019-12-31 16:22:55
为什么不用C++呢