luogu#P9163. 「INOH」Round 1 - 纽结
「INOH」Round 1 - 纽结
Problem Description

The figure above shows the planar projections of two knots.
We observe that a knot can be described by basic crossing points, and each crossing point is a double point.
That is, we can use a point to represent a crossing, and connect crossings with edges of different types.
You can see that each point has four exits, and exits are connected to exits. Among these four edges, two are on the upper layer and two are on the lower layer.
We use an ordered pair to represent such an exit.
Here, is the index of the point, and . Also, we define that and are the two upper edges, and and are the two lower edges.
We also observe that a knot has two ends. These two ends can be connected to the outside. For convenience, we use and to represent these two ends.
Now you are given such a knot. You need to answer: when we pinch the two ends and pull hard, is it a slipknot (live knot) or a dead knot?
If it is a slipknot, output Yes. If it is a dead knot, output No.
Input Format
The first line contains the number of test cases .
For each test case, the first line contains , the number of nodes.
Then follow lines. On the -th line there are eight integers , describing the corresponding exits connected to exits through of node .
In the -th line, the first pair means that exit of node is connected to exit of node , and so on.
Output Format
Output lines in total. Each line is Yes or No.
1
3
-1 0 2 2 2 0 3 0
1 2 3 2 1 1 3 1
1 3 2 3 2 1 -2 0
No
1
3
-1 0 2 0 2 2 3 0
1 1 3 1 1 2 3 2
1 3 2 1 2 3 -2 0
Yes
Hint
Constraints
This problem uses bundled testdata.
- Subtask 0 (20 pts): , .
- Subtask 1 (20 pts): , .
- Subtask 2 (10 pts): , , and the testdata is guaranteed to be randomly generated.
- Subtask 3 (50 pts): , .
Sample Explanation
In sample 1 (the left figure), it is a dead knot.
In sample 2 (the right figure), it is a slipknot (live knot).

Translated by ChatGPT 5