#P4099. [HEOI2013] SAO
[HEOI2013] SAO
Description
Welcome to SAO (Strange and Abnormal Online). This is a VR MMORPG with levels. However, deciding the order to challenge the levels is a big problem.
The game imposes constraints on the order of levels, such as level must be challenged before level , or you can attempt level only after finishing level . Moreover, if we ignore the directions of the constraints, then under these constraints, any two levels are connected in some way. That is, we cannot partition all levels into two nonempty disjoint subsets such that there is no constraint between the two subsets.
Input Format
The first line contains an integer , the number of test cases.
For each test case, the first line contains an integer , the number of levels. Then follow lines, each in the form , where and , and is or , meaning level must be completed before (if is ) or after (如果 is ) level .
Output Format
For each test case, output one integer on a single line: the number of valid orders to conquer the levels, output .
2
5
0 < 2
1 < 2
2 < 3
2 < 4
4
0 < 1
0 < 2
0 < 3
4
6
Hint
- For of the testdata, .
- For of the testdata, .
- For another of the testdata, it is guaranteed that is only and .
- For of the testdata, and .
Translated by ChatGPT 5
京公网安备 11011102002149号