格式要求是:DO NOT output any blanks.
千万不要理解成:DO NOT output any blanks or blank lines.
我理解成:不要输出多余的行。
# include <stdio.h>
# define MAXN 1002
int father[MAXN];
int main()
{
int N, M, x, y, T, i, cnt;
scanf("%d", &T);
while (T--)
{
cnt = 0;
scanf("%d%d", &N, &M);
for (i = 1; i <= N; ++i)
father[i] = i;
while (M--)
{
scanf("%d%d", &x, &y);
while (x != father[x]) x = father[x];
while (y != father[y]) y = father[y];
if (x != y)
{
father[y] = x;
++cnt;
}
}
printf("%d\n", N-cnt);
// if (T) printf("\n");
}
return 0;
}