创想实验室
我们都是梦想家

Sherlock

描述

There is a little sister in the laboratory, who is particularly keen on Sherlock and she watches it again and again every year in the summer vacation. As a fan of the great detective, she decides to play a game with her partners. The rules are as follows: There are N persons in total, and each person has a unique ID from 1 to N. Everyone will say, I know the K-th person tells the truth. or I know the K-th person is lying. It is known that only one person is lying and all the others speak the truth. Now you must nd out who is lying.

输入

The rst line of the input contains a single integer T (1 ≤ T ≤ 10), the number of test cases. T test cases follow. The rst line of each case contains a single integer N (3 ≤ N ≤ 100), the number of persons participating in the game. In the following N lines, the i-th line describes what the i-th person said. Each line contains two integers K and F (1 ≤ K ≤ N,0 ≤ F ≤ 1), separated by a single space. If F = 1, the i-th person says I know the K-th person tells the truth. If F = 0, the i-th person says I know the K-th person is lying. It is guaranteed that either F = 1 or K 6= i, which means no person will say that himself is lying. It is also guaranteed that exactly one person is lying.

输出

For each test case, output a line containing a single integer, denoting the ID of the person that is lying.

样例输入

样例输出

题解

对于每一个人都假设说谎,去判断是否成立即可

代码

 

网站所发布的代码已提交通过,代码可能经过修改防止抄袭,未经允许不得转载:创想实验室 » Sherlock
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址