#include <iostream>
#include <cstdio>
using namespace std;
#define MAXN 1001
//连通分量
//n个连通分量需要n-1条路
int city[MAXN];
struct edge{
int head;
int tail;
//从1开始
};
int gethead(int j){
if(city[j]==j){
return j;
}else{
return city[j]=gethead(city[j]);
}
}
void build(int a,int b){
if(gethead(a)!=gethead(b)){
city[gethead(a)]=gethead(b);
}
}
int main()
{
int N,M,K;
scanf("%d %d %d",&N,&M,&K);
edge way[MAXN*MAXN/2];
for(int i=0;i<M;i++){
int a,b;
scanf("%d %d",&a,&b);
way[i].head=a;
way[i].tail=b;
}
for(int i=0;i<K;i++){
int fail;
scanf("%d",&fail);
for(int j=1;j<=N;j++){
city[j]=j;//每个城市连通分量是它自己
}
for(int j=0;j<M;j++){
if(way[j].head==fail||way[j].tail==fail){
continue;
}//不会对已被占领的边做出反应
build(way[j].tail,way[j].head);//查并集建立
}
int res=0;
for(int j=1;j<=N;j++){
if(city[j]==j){
res++;
}
}
cout<<res-2<<endl;
}
return 0;
}
好吧
终于体会到cin>>对于程序运行速度的影响了
老老实实用scanf