您的位置:首页 > 其它

UVA 1160 X-Plosives

2013-03-27 20:19 357 查看
大意略。

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;

const int maxn = 100010;

int pa[maxn];

void init()
{
	for(int i = 0; i < 100001; i++) pa[i] = i; 
}

int find(int x)
{
	return x == pa[x] ? x : pa[x] = find(pa[x]);
}

int main()
{
	int x, y;
	while(~scanf("%d", &x))
	{
		init();
		int ans = 0;
		while(x != -1)
		{
			scanf("%d", &y);
			x = find(x), y = find(y);
			if(x != y) pa[x] = y;
			else ans++;
			scanf("%d", &x);
		}
		printf("%d\n", ans);
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: