Sorting Algorithm with constraints
In other words, you are given a directed graph, and you want to know:


Whether there are any directed cycles, i.e., whether your graph is a DAG.
Assuming there are no directed cycles, whether the corresponding partial order is a linear order.


As KWillets comments, this is just topological ordering. In your case, to find whether your digraph is a DAG supporting a unique topological ordering, try the following algorithm:


Verify that there is a unique source (a node with no incoming edges).
Remove the unique source, and repeat.


This succeeds iff your digraph is a DAG which has a unique topological ordering.