题意:
N children are playing Rochambeau (scissors-rock-cloth) game with you. One of them is the judge. The rest children are divided into three groups (it is possible that some group is empty). You don’t know who is the judge, or how the children are grouped. Then the children start playing Rochambeau game for M rounds. Each round two children are arbitrarily selected to play Rochambeau for one once, and you will be told the outcome while not knowing which gesture the children presented. It is known that the children in the same group would present the same gesture (hence, two children in the same group always get draw when playing) and different groups for different gestures. The judge would present gesture randomly each time, hence no one knows what gesture the judge would present. Can you guess who is the judge after after the game ends? If you can, after how many rounds can you find out the judge at the earliest?
Input
Input contains multiple test cases. Each test case starts with two integers N and M (1 ≤ N ≤ 500, 0 ≤ M ≤ 2,000) in one line, which are the number of children and the number of rounds. Following are Mlines, each line contains two integers in [0, N) separated by one symbol. The two integers are the IDs of the two children selected to play Rochambeau for this round. The symbol may be “=”, “>” or “<”, referring to a draw, that first child wins and that second child wins respectively.
Output
There is only one line for each test case. If the judge can be found, print the ID of the judge, and the least number of rounds after which the judge can be uniquely determined. If the judge can not be found, or the outcomes of the M rounds of game are inconsistent, print the corresponding message.
Sample Input
3 3 0<1 1<2 2<0 3 5 0<1 0>1 1<2 1>2 0<2 4 4 0<1 0>1 2<3 2>3 1 0
Sample Output
Can not determine Player 1 can be determined to be the judge after 4 lines Impossible Player 0 can be determined to be the judge after 0 lines
(太晚了。想了一下做法,反正还是带权并查集,就不写代码了,写写思路吧)
思路:明显带权并查集,但是怎么带呢,因为剪刀石头布是相互克制的,所以连续的<,每隔三个位置一循环
例如:石头<布<剪刀<石头<布...,所以可以带的权值是距离头结点的距离(%3的值即可,想想为甚,比较好理解)
头结点不同的两个点直接连接,
例:l>r,u=find(l),v=find(r); u!=v f[u]=v;dis[u]=((dis[r]+1-dis[l])%3+3)%3;
l=r u!=v f[u]=v;dis[u]=((dis[r]-dis[l])%3+3)%3;
u==v时判断是否l,r的dis的相对大小是否符合。
大体就是这样的思路
但是还有裁判,,不一定是什么,怎么搞呢,看了题解,因为n很小,500,所以可以枚举每个人当裁判的情况,裁判参与的局不考虑,进行判断是否产生矛盾。
当然不能确定情况就是存在至少两个人,当裁判的时候,都没有矛盾。
Impossible的情况是,每个人当裁判都会产生矛盾
能确认裁判i的情况就是,当且仅当i当裁判时,没有矛盾。否则都有矛盾。