coreBugZJ

此 blog 已弃。

KILLER,HUST Monthly 2011.04.09 之 B,1432

KILLER

Time Limit: 1 Sec Memory Limit: 128 MB
Submissions: 519 Solved: 147

Description

There are n Killers in a city.Each killer want to kill a killer(maybe a suicide) and if A want to kill B , there will not be another killer want to kill B. Killers kill their aim by turn and we ensure that in the end ,there will be at most one killer still alive. If there is one killer not be killed in the end, he will be the king of killer.Can you tell me the number of killer who can be the king of killer?

 

Input

 

The first line is an integer T indicating the number of test cases.

Next T block, each block is a test case.

First line of each block is a integer N ( 1 <= N <= 100000 )

Followed by N lines, each line is two integers A B , indicating that A will kill B.

 

Output

The number of killer who can be the king of killer.

 

Sample Input

2
2
1 2
2 1
1
1 1

Sample Output

2
0
 
 1#include <iostream>
 2#include <cstdio>
 3
 4using namespace std;
 5
 6int main() {
 7        int td, n, ans, a, b;
 8        scanf( "%d"&td );
 9        while ( td-- > 0 ) {
10                scanf( "%d"&n );
11                ans = n;
12                while ( n-- > 0 ) {
13                        scanf( "%d%d"&a, &b );
14                        if ( a == b ) {
15                                --ans;
16                        }

17                }

18                printf( "%d\n", ans );
19        }

20        return 0;
21}

22

posted on 2011-04-09 19:07 coreBugZJ 阅读(84) 评论(0)  编辑 收藏 引用 所属分类: ACM


只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理