#include <iostream>
#include <cstring>
using namespace std;
const int N = 1010;
int map[N][N];
int vis[N];
int count;
int n, m, k;
void dfs(int x)
{
vis[x] = true;
for (int i = 1; i <= n; i++)
{
if (!vis[i] && map[x][i])
dfs(i);
}
}
int main()
{
cin >> n >> m >> k;
for (int i = 1; i <= m; i++)
{
int x, y;
cin >> x >> y;
map[x][y] = 1, map[y][x] = 1;
}
for (int i = 1; i <= k; i++)
{
if (i != 1)
puts("");
memset(vis, 0, sizeof vis);
count = 0;
int x;
cin >> x;
vis[x] = true;
for (int i = 1; i <= n; i++)
{
if (!vis[i])
{
dfs(i), count++;
}
}
cout << count - 1;
}
}
solution#include <iostream>#include <cstring>using namespace std;const int N = 1010;int map[N][N];int vis[N];int count;int n, m, k;void dfs(int x){ vis[x] = true; for (int i = 1; i <= n; i++) { if (!vis[i] &