Violet___Evergarden @ 2021-07-15 18:27:36
#include<bits/stdc++.h>
using namespace std;
const int kMaxN=4e5+1;
int n,m,f[kMaxN],cnt,ans[kMaxN];
struct EDGE
{
int nw,to,nt;
}e[kMaxN*2];
int hd[kMaxN],edge,k,bbk[kMaxN];
bool bk[kMaxN];
void Add(int x,int y)
{
e[++edge].nw=x;
e[edge].nt=hd[y];
e[edge].to=y;
hd[x]=edge;
}
int Find(int k)
{
return f[k]==k?k:f[k]=Find(f[k]);
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
f[i]=i;
hd[i]=-1;
}
for(int i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
Add(x,y);
Add(y,x);
}
cin>>k;
cnt=n-k;
for(int i=1;i<=k;i++)
{
int a;
cin>>a;
bbk[i]=a;
bk[a]=true;
}
for(int i=1;i<=2*m;i++)
{
if(bk[e[i].nw]==false&&bk[e[i].to]==false&&Find(e[i].nw)!=Find(e[i].to))
{
f[Find(e[i].nw)]=Find(e[i].to);
cnt--;
}
}
ans[k+1]=cnt;
for(int i=k;i>=1;i--)
{
bk[bbk[i]]=false;
cnt++;
for(int j=hd[bbk[i]];j!=-1;j=e[j].nt)
{
if(bk[e[j].to]==false&&Find(bbk[i])!=Find(e[j].to))
{
cnt--;
f[Find(bbk[i])]=Find(e[j].to);
}
}
ans[i]=cnt;
}
for(int i=1;i<=k+1;i++)
{
cout<<ans[i]<<endl;
}
return 0;
}
没过样例,交上去是这样的
by jiang_cheng @ 2021-07-16 14:05:29
星球用
by jiang_cheng @ 2021-07-16 14:06:50
@Time_Limit_Enough
by Violet___Evergarden @ 2021-07-16 14:17:17
@jiang_cheng orz,tql
by Violet___Evergarden @ 2021-07-16 14:17:36
@jiang_cheng 感谢dalao
by Violet___Evergarden @ 2021-07-16 14:23:17
改了以后似乎还是错的?
by Violet___Evergarden @ 2021-07-16 14:30:22
@jiang_cheng
by jiang_cheng @ 2021-07-16 14:42:48
不知道,问问这位大佬—》@万物皆可AC