记录编号 307024 评测结果 AAAAAAAAAA
题目名称 爆炸化合物 最终得分 100
用户昵称 GravatarNVIDIA 是否通过 通过
代码语言 C++ 运行时间 0.482 s
提交时间 2016-09-13 16:34:31 内存使用 0.70 MiB
显示代码纯文本
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<cctype>
using namespace std;
int f[100005],i,n,m,sum=0,fx,fy;
int getf(int v)
{
	if(f[v]==v)return v;
	return f[v]=getf(f[v]);
}
int main()
{	
freopen("explosion.in","r",stdin);
freopen("explosion.out","w",stdout);
for(i=0;i<100005;i++)
f[i]=i;
while(scanf("%d",&n)!=EOF && n!=-1)
{
	
     cin>>m;
	fx=getf(n);
	fy=getf(m);
	if(fx==fy)sum++;
	else f[fx]=fy;
}
cout<<sum;
return 0;
}