当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3305:Surveillance

题目描述

See.Eye.A, the world's biggest independent intelligence agency, is located in a very large underground building. Recently, due to the large amount of secret documents kept in different departments and due to some recent strange activities in the building, the managers of See.Eye.A have decided to install an advanced surveillance system to monitor all the activities within the building. But lack of budgets has forced them to accomplish this task with the minimum expenses possible.

To be more specific, the building is consisted of a set of long passages containing doors at their two ends. If two passages i and j share the same door, then one can enter passage i from j or exit from passage i to j through that door. It should be noted that there is exactly one simple path through passages and other doors between each pair of doors (i.e. the structure of the passages and the doors is like a tree). Also note that the doors are made circular and as a result, more than 2 passages can share the same door. In addition, to extend the building in future, a door may be a dead-end i.e. a door that does not connect its passage to another one.

The surveillance system consists of a set of cameras which should be installed in different parts of the building so that all parts of the building, including the doors and passages, can be monitored. After a thorough analysis, the engineers of See.Eye.A decided that a camera should only be installed on either above one of the doors or in the middle of a passage. Note that if a camera is installed above a door, then all the passages sharing that door, the doors in the other ends of these passages, and the door itself can be monitored. On the other hand, if a camera is installed in the middle of a passage, then passage itself, doors at its both ends and all the adjacent passages sharing doors with it can be monitored.

Now, they want to know the minimum number of cameras that can be installed to monitor all the doors and passages of the building, and they hired you to write a program to accomplish this task for them.

输入解释

The first line of input contains a single integer T, which is the number of test cases. Each test case starts with a line containing one integer 1 ≤ P ≤ 100 which is the number of passages in the building, followed by P lines each containing a pair of integers 0 ≤ A, B ≤ 1,000,000,000 which are the unique IDs of the two doors at either side of each passage.

输出解释

For each test-case, your program should output the minimum number of needed cameras to monitor all the building, in a single line.

输入样例
2
7
10 20
20 30
30 4
4 55
55 60
60 1
1 1024
9
10 30
20 30
30 40
40 50
50 60
50 70
40 80
80 90
80 100
输出样例
3
3

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3305

最后修改于 2020-10-29T06:58:12+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536