如果失去某个城市后分为k个联通块,则最少需k-1条边使其联通
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 1010;
vector<int> mp[MAXN];
bool vis[MAXN];
void dfs(int i, int c) {
vis[i] = true;
for (vector<int>::iterator it = mp[i].begin(); it != mp[i].end(); it++)
if (*it != c && !vis[*it])
dfs(*it, c);
}
int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
while (m--) {
int x, y;
scanf("%d%d", &x, &y);
mp[x].push_back(y);
mp[y].push_back(x);
}
while (k--) {
int c;
scanf("%d", &c);
int ans = 0;
memset(vis, false, sizeof(vis));
for (int i = 1; i <= n; i++)
if (i != c && !vis[i]) {
ans++;
dfs(i, c);
}
printf("%d\n", ans-1);
}
return 0;
}