A. Sereja and Bottles

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Sereja and his friends went to a picnic. The guys had n soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles.

Sereja knows that the i-th bottle is from brand ai, besides, you can use it to open other bottles of brand bi. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle.

Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of bottles. The next n lines contain the bottles' description. The i-th line contains two integers ai, bi (1 ≤ ai, bi ≤ 1000) — the description of the i-th bottle.

Output

In a single line print a single integer — the answer to the problem.

Sample test(s)
input
4
1 1
2 2
3 3
4 4
output
4
input
4
1 2
2 3
3 4
4 1
output
0

解题说明:题目的意思虽然是开瓶盖,其实只需要保证每一行中这一对数不同即可,因为第一个瓶子无论是否打开都可以打开后一个瓶子。于是问题转变为判断一组数中,每一行中的一对数不同的个数,再用总数减去即为答案。


#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;

int main()
{
	int an=0,n,y,i,j,k,x,a[1001],b[1001];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if((a[i]==b[j])&&(i!=j))
			{
				an++;
				break;
			}
		}
	}	
	printf("%d\n",n-an);
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值