给定 个变量和 个不等式。其中 ,变量分别用前 的大写英文字母表示。
不等式之间具有传递性,即若 且 ,则 。
请从前往后遍历每对关系,每次遍历时判断:
* 如果能够确定全部关系且无矛盾,则结束循环,输出确定的次序; * 如果发生矛盾,则结束循环,输出有矛盾; * 如果循环结束时没有发生上述两种情况,则输出无定解。
输入包含多组测试数据。
每组测试数据,第一行包含两个整数 和 。
接下来 行,每行包含一个不等式,不等式全部为小于关系。
当输入一行 时,表示输入终止。
每组数据输出一个占一行的结果。
结果可能为下列三种之一:
"Sorted sequence determined after t relations: yyy...y."
t
yyy
y
"Inconsistency found after t relations."
"Sorted sequence cannot be determined."
4 6 A<B A<C B<C C<D B<D A<B 3 2 A<B B<A 26 1 A<Z 0 0
Sorted sequence determined after 4 relations: ABCD. Inconsistency found after 2 relations. Sorted sequence cannot be determined.
6 6 A<F B<D C<E F<D D<E E<F 0 0
Inconsistency found after 6 relations.
,变量只可能为大写字母 AZ。
A
Z
浴谷原题
某POJ原题