A. Sereja and Bottles

来源:互联网 发布:用php写99乘法表思路 编辑:程序博客网 时间:2024/05/16 14:53

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
41 12 23 34 4
output
4
input
41 22 33 44 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;}