Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

CF 315A(Sereja and Bottles-开易拉罐)

$
0
0

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

水题,直接数。注意b[i]对a[j]。

考场上有一大堆人这题各种卖萌,专业Hack30年……

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define MAXN (100+10)
#define MAXM (1000+10)
int a[MAXN],b[MAXN],n;
bool b2[MAXN]={0};
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
    memset(b2,0,sizeof(b2));
    cin>>n;
    For(i,n) cin>>a[i]>>b[i];
    For(i,n)
        For(j,n)
        {
            if (i!=j&&b[i]==a[j]) b2[j]=1;
        }
    int ans=0;
    For(i,n) ans+=b2[i];
    cout<<n-ans<<endl;
	return 0;
}




作者:nike0good 发表于2013-6-8 8:28:08 原文链接
阅读:23 评论:0 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>