CodeForces
- 315A

Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit Status

Description

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 Input

Input
4
1 1
2 2
3 3
4 4
Output
4
Input
4
1 2
2 3
3 4
4 1
Output

0

理解题意就可以

/*
Author: 2486
Memory: 812 KB Time: 60 MS
Language: GNU G++ 4.9.2 Result: Accepted
Public: No Yes
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1000+5;
bool vd[maxn][maxn];
struct fs{
int a,b;
}fss[maxn];
int main() {
int b,n;
scanf("%d",&n);
memset(vd,false,sizeof(vd));
for(int i=1; i<=n; i++) {
scanf("%d%d",&fss[i].a,&fss[i].b);
vd[fss[i].b][fss[i].a]=true;
}
bool flag=true;
int cnt=0;
for(int i=1; i<=n; i++) {
flag=false;
for(int j=1; j<=n; j++) {
if(i==j)continue;
if(fss[i].a==fss[j].b) {
flag=true;
break;
}
}
if(flag)cnt++;
}
printf("%d\n",n-cnt);
return 0;
}

最新文章

  1. (。・・)ノ~java常见错误
  2. cxf+spring+数字签名开发webservice(一)
  3. PHP中的数组(一)
  4. android 带边框的圆角按钮
  5. Linux多线程——使用互斥量同步线程
  6. nginx模块开发获取post参数
  7. adt-bundle更新eclipse,以及搭建android环境
  8. 老李分享:持续集成学好jenkins之解答疑问
  9. 第4天:JS入门-给div设置宽高背景色
  10. MST系列
  11. Sort of Python
  12. Flink解析kafka canal未压平数据为message报错
  13. windows server 2008 R2服务器无法通过ShellClass获取mp3音乐时长
  14. tmux 没有默认配置文件。
  15. jQuery中event.target和this的区别
  16. python学习(十)
  17. linux 第七周 总结及实验
  18. 几种TCP连接终止
  19. SQL语法语句总结(《SQL必知必会》读书笔记)
  20. 让MySql支持Emoji表情存储

热门文章

  1. Swift学习笔记(二十二)——字典的基本操作
  2. sublime界面主题
  3. 一个域名如何解析到多个ip地址
  4. Ubuntu16.04系统下汉字显示为方框解决办法(图文详解)
  5. WPF下DataGrid的简单应用
  6. SQLServer 添加序号列
  7. P3399 丝绸之路
  8. 如何使用fetch
  9. jquey中的事件绑定
  10. 安装pywin32