#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
int N,M,K;
vector<int> v[1005];
int book[1005]={0};
int x;
void dfs(int id)
{
if(id==x)//碰到被删的点,头也不回的就return
return;
book[id]=1;//访问语句
for(int i=0;i<v[id].size();i++)
{
if(book[v[id][i]]==0)
dfs(v[id][i]);
}
return;
}
int main()
{
//freopen("in.txt","r",stdin);
scanf("%d %d %d",&N,&M,&K);
for(int i=0;i<M;i++)
{
int t1,t2;
scanf("%d %d",&t1,&t2);
v[t1].push_back(t2);
v[t2].push_back(t1);
}
while(K--)
{
memset(book,0,sizeof(book));
scanf("%d",&x);
int cou=0;
for(int i=1;i<=N;i++)
{
if(book[i]==0&&i!=x)
{
dfs(i);
cou++;
}
}
printf("%d\n",cou-1);
}
return 0;
}
1013. Battle Over Cities (25)---dfs
最新推荐文章于 2019-04-29 10:00:54 发布