#P1347. 排序
排序
Description
An ascending sorted sequence of distinct values is a sequence whose elements strictly increase from left to right. For example, an ordered sequence means , , . In this problem, you are given a series of relations of the form , and you are asked to determine whether these relations are sufficient to determine the order of the sequence.
Input Format
The first line contains two positive integers and . Here, is the number of elements to sort, . The -st to the -th elements are represented by uppercase letters . The integer is the number of relations of the form .
The next lines each contain exactly characters: an uppercase letter, the character <, and another uppercase letter, representing a relation between two elements.
Output Format
If the first relations are sufficient to determine the order of the elements yyy...y (e.g., ABC), output
Sorted sequence determined after x relations: yyy...y.
Here, means the number of relations considered (the first relations).
If a contradiction is detected within the first relations (e.g., , , ), output
Inconsistency found after x relations.
Here, has the same meaning as above.
If the order of the elements cannot be determined after all relations, output
Sorted sequence cannot be determined.
(Hint: Once the order of the elements is determined, you can terminate the program immediately. You do not need to consider contradictions that may appear after that.)
Input Format
Output Format
4 6
A<B
A<C
B<C
C<D
B<D
A<B
Sorted sequence determined after 4 relations: ABCD.
3 2
A<B
B<A
Inconsistency found after 2 relations.
26 1
A<Z
Sorted sequence cannot be determined.
Hint
.
Translated by ChatGPT 5
京公网安备 11011102002149号