返回

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

发布时间:2022-10-26 12:13:25 314

A. Sereja and Bottles

time limit per test

memory limit per test

input

output

n

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

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
#include
#include
#include
#include
#include
#include
#include
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;
}

 

 

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像
精选文章
thumb 中国研究员首次曝光美国国安局顶级后门—“方程式组织”
thumb 俄乌线上战争,网络攻击弥漫着数字硝烟
thumb 从网络安全角度了解俄罗斯入侵乌克兰的相关事件时间线