#P14690. [ICPC 2025 Yokohama R] Membership Structure of a Secret Society
[ICPC 2025 Yokohama R] Membership Structure of a Secret Society
题目描述
A secret society with an undisclosed name was established in the year 1899 by a single founder, whose name is also kept secret. Subsequent members have joined the society through recommendations of existing members.
One unique rule for joining the society has been strictly enforced: Recommendations can be made by one or more existing members, but the same member group can recommend only one new member. For example, if a member was allowed to join upon the recommendation by a group of existing members , no other persons can be allowed by the same recommender group. It is perfectly acceptable, however, for a group to recommend another new member. Although the set is a subset of , they are distinct sets. For consistency, the group of recommenders of the founder is considered to be the empty set.
Through investigation of this secret society, you have obtained several information fragments representing some part of the membership structure of the society. Each information fragment takes one of the following forms of statements, in which the symbols , and are integers designating certain members of the society.
-
recommend
meaning that the member belongs to the group that recommended the member to join. -
not-recommend
meaning that the member does not belong to the group that recommended the member to join. -
intersection
meaning that the group of the recommenders of the member is the set intersection of recommender group of and that of . In other words, all of those who recommended also recommended both and , and all of those who recommended both and also recommended .
Two or more occurrences of the same integer mean the same member, even in different statements. On the other hand, two or more different integers may be aliases of the same person, even in a single statement.
The obtained information may be partial, that is, the recommendations of some members may be missing, and, moreover, there may be some members not mentioned in any of the statements.
As the information sources are not necessarily reliable, some false information might have crept in. You would like to know whether these statements are consistent, that is, whether there can be a recommendation relationship consistent with all of these statements.
输入格式
The input contains one or more test cases. The first line of the input contains an integer (), which is the number of test cases. The descriptions of the test cases follow, each in the following format.
The first line contains a single integer , the number of statements (). Each of the following lines is in either of the formats "recommend ", "not-recommend ", or "intersection ", with all of , , and being integers between 1 and , inclusive.
The sum of 's over all the test cases does not exceed 3000.
输出格式
For each test case, output in one line if the situation described in the statements is possible, and output , otherwise.
3
2
recommend 1 2
not-recommend 1 2
2
recommend 1 2
recommend 2 1
3
intersection 1 2 2
recommend 1 3
not-recommend 2 3
no
no
no