#K77487. Marathon Ranking Consistency
Marathon Ranking Consistency
Marathon Ranking Consistency
In this problem, you are given n participants and m pairwise comparisons of their finishing order in a marathon. Each comparison is represented as a tuple \( (a, b) \), meaning participant a finished before participant b. Your task is to determine whether there exists a valid ordering of all participants that is consistent with all the reported comparisons. In other words, check if the directed graph formed by these comparisons is a Directed Acyclic Graph (DAG).
If the comparisons are consistent with a valid ordering, output "consistent"; otherwise, output "inconsistent".
inputFormat
The input is read from stdin as follows:
- The first line contains two integers \( n \) and \( m \) — the number of participants and the number of comparisons, respectively.
- Each of the following \( m \) lines contains two integers \( a \) and \( b \), indicating that participant \( a \) finished before participant \( b \).
outputFormat
Output a single line to stdout containing either "consistent" if a valid ordering exists, or "inconsistent" if it does not.
## sample4 3
0 1
1 2
2 3
consistent
</p>