由比滨丶雪乃 @ 2019-08-08 21:39:35
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cmath>
#include <vector>
#define ll long long
#define maxn 400010
using namespace std;
int head[maxn],cnt;
int fa[maxn];
int sum;
int x,y;
int k;
int t;
int f[maxn],ans[maxn];
bool check[maxn];
int read()
{
char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
int num=0;
while(ch>='0'&&ch<='9') num=(num<<3)+(num<<1)+(ch^48),ch=getchar();
return num;
}
struct Edge
{
int from;
int to;
int next;
}edge[maxn];
void add(int u,int v)
{
edge[cnt].to=v;
edge[cnt].from=u;
edge[cnt].next=head[u];
head[u]=cnt++;
}
int find(int x)
{
if(x==fa[x]) return x;
fa[x]=find(fa[x]);
return fa[x];
}
void bing(int x,int y)
{
x=find(x);
y=find(y);
if(x==y) return;
sum--;
fa[x]=y;
}
int main()
{
int n,m;
n=read();
m=read();
for(int i=1;i<=n;i++)
{
fa[i]=i;
head[i]=-1;
}
for(int i=1;i<=m;i++)
{
x=read();
y=read();
add(x,y);
add(y,x);
}
k=read();
sum=n-k;
for(int i=1;i<=k;i++)
{
t=read();
check[t]=true;
f[i]=t;
}
for(int i=1;i<=2*m;i++)
{
if(!check[edge[i].from]&&!check[edge[i].to])
{
bing(edge[i].from,edge[i].to);
}
}
ans[k+1]=sum;
for(int i=k;i>=1;i--)
{
int t=f[i];
sum++;
check[t]=false;
for(int i=head[t];i!=-1;i=edge[i].next)
{
if(!check[edge[i].from]&&!check[edge[i].to])
{
bing(edge[i].from,edge[i].to);
}
}
ans[i]=sum;
}
for(int i=1;i<=k+1;i++)
{
printf("%d\n",ans[i]);
}
return 0;
}
by 由比滨丶雪乃 @ 2019-08-08 21:55:20
玄学!!!!!!
by 由比滨丶雪乃 @ 2019-08-08 21:56:15
for(int i=0;i<n;i++)
{
fa[i]=i;
head[i]=-1;
}
for(int i=0;i<m;i++)
{
x=read();
y=read();
add(x,y);
add(y,x);
}
当我从0开始循环的时候,就跑的飞快,从1开始就卡成屎凸(艹皿艹 )
by JT_kk @ 2019-08-08 22:00:10
@由比滨丶雪乃 因为题中点的范围是
by 由比滨丶雪乃 @ 2019-08-08 22:01:12
@JT_kk 好吧= =
日常眼瞎= =
by 由比滨丶雪乃 @ 2019-08-08 22:06:16