#SDNU1031. 字母排序
字母排序
Description
有若干个字母,已知它们中某些字母之间的前后关系,求它们的排列顺序。
input
输入数据包含若干组。
每组数据第一行两个整数、,为字母的个数及已知条件的个数,字母为从 开始的 个字母。 均为 表示输入结束。
之后 行,为一个条件,格式为:字母<字母,或字母>字母,如 ,代表 在 的前面, 代表 在 的后面。
Output
对于每组输入数据,输出包含一行,若确定了字母的顺序,则输出:
Sorted sequence determined after xxx relations: yyy…y.
若发现了矛盾,则输出:
Inconsistency found after xxx relations.
若无法确定全部字母的顺序,则输出:
Sorted sequence cannot be determined.
其中, 为已读入的条件的个数, 为排好序的字母序列。
Samples
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.