Sort items based on dependency Goal

Sort a list of items ensuring that each item is listed after its specified dependencies.

Input

An array of arrays of integers, where each integer specifies the 0-based or 1-based index of another item that this item must come after.  The input may be an array or string or anything else human readable.

For example, a 0-based input:

[
  [ 2 ],    // item 0 comes after item 2
  [ 0, 3 ], // item 1 comes after item 0 and 3
  [ ],      // item 2 comes anywhere
  [ 2 ]     // item 3 comes after item 2
]


Assume there are no circular dependencies, there is always at least one valid order.

Output

The numbers in order of dependency.  An ambiguous order does not have to be deterministic.  The output may be an array or text or anything else human readable.

Only one order should be given in the output, even where there are multiple valid orders.

Possible outputs for the above input include:

[ 2, 3, 0, 1 ]
[ 2, 0, 3, 1 ]


Scoring

A function or program that completes this in the least number of bytes wins the glory of acceptance.  The deadline is in 6 days.
Pyth, 21 bytes

hf.A.e!f&gt;xYTxkTbQ.plQ




                    Q  input
                   l   length of input array
                 .p    all permutations of [0, 1, ..., lQ-2, lQ-1]
hf                     find the first permutation for which...
    .e          Q        map over the input array with indices...
       f       b           find all elements in each input subarray where...
        &gt;xYT                 index of dependency is greater than...
            xkT              index of item
      !                    check whether resulting array is falsy (empty)
  .A                     is the not-found check true for [.A]ll elements?


Test:

llama@llama:~$ echo '[[2],[0,3],[],[2]]' | pyth -c 'hf.A.e!f&gt;xYTxkTbQ.plQ' 
[2, 0, 3, 1]