The problem
I have prepared a problem as follow: There is this secret sequence $$$S$$$ consists of $$$N$$$ distinct numbers. Given a matrix $$$G$$$ of size $$$N \times N$$$, where $$$G_{i,j}=$$$'\t{Y}' if $$$S_i>S_j$$$. Otherwise, $$$G_{i,j}=$$$'\t{?}', meaning we have no information about the relation of $$$S_i$$$ and $$$S_j$$$, whether they are larger or smaller. You need to output a sequence $$$P = {P_1, P_2, ..., P_n}$$$, such that $$$S_{P_1} > S_{P_2} > ... > S_{P_n}$$$, or report that it is impossible to determined exactly the order.
Example
\begin{array}{|c|c|c|} \hline G & 1 & 2 & 3 & 4 \cr \hline 1 & ? & ? & ? & ? \cr \hline 2 & ? & ? & Y & Y \cr \hline 3 & Y & ? & ? & Y \cr \hline 4 & Y & ? & ? & ? \cr \hline \end{array} The above input yeilds the answer $$$P={2,3,4,1}$$$ which corresponds to $$$S_2 > S_3 > S_4 > S_1$$$. This is the only possible answer.
Constraints:
- $$$(1 \leq N \leq 400)$$$
- Time limit: 1s