2414419_tle.cc
来自「北大大牛代码 1240道题的原代码 超级权威」· CC 代码 · 共 34 行
CC
34 行
#include <stdio.h>
int res[50001];
int main()
{
int n, m, ans, t;
int a, b, i, j, cas = 1;
while(scanf("%d%d",&n,&m)==2)
{
if(!m&&!n)
return 1;
for(i = 0; i <= n; i++)
res[i] = i;
ans = n;
for(i = 0; i < m; i++)
{
scanf("%d%d",&a,&b);
t = res[b];
if(res[a]==res[b])
continue;
for(j = 1; j <= n; j++)
{
if(res[j]==t)
res[j] = res[a];
}
ans--;
}
printf("Case %d: %d\n",cas++,ans);
}
return 1;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?