huang_jr @ 2022-03-01 23:03:34
评测链接
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,k,f[400005],s[400005],build[400005],sum[400005],ans[400005];
vector<ll> g[400005];
ll find(ll kk)
{
if (f[kk]!=kk)
f[kk]=find(f[kk]);
return f[kk];
}
int main()
{
cin>>n>>m;
for (ll i=0;i<n;i++)
{
f[i]=i;
sum[i]=1;
}
for (ll i=0;i<m;i++)
{
ll a,b;
cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
cin>>k;
for (ll i=0;i<k;i++)
{
cin>>s[i];
build[s[i]]=1;
}
ll cnt=n-k;
for (ll i=0;i<n;i++)
if (build[i]==0)
for (ll j=0;j<g[i].size();j++)
if (build[g[i][j]]==0&&find(g[i][j])!=find(i))
{
f[find(g[i][j])]=find(j);
cnt--;
}
ans[k]=cnt;
for (ll i=k-1;i>=0;i--)
{
build[s[i]]=0;
cnt++;
for (ll j=0;j<g[s[i]].size();j++)
if (build[g[s[i]][j]]==0&&find(g[s[i]][j])!=find(s[i]))
{
f[find(g[s[i]][j])]=find(s[i]);
cnt--;
}
ans[i]=cnt;
}
for (ll i=0;i<=k;i++)
cout<<ans[i]<<endl;
return 0;
}
by houran @ 2022-05-02 17:11:42
by You_Quiet @ 2022-11-12 08:49:03
和我错的一样,输出都差不多!!
要不看看我的,看看有什么错的一样的?
rt