title: Directed acyclic graph: find all paths from a specific node
body: <p>How do I find all the paths from a specific node (node 36 in the example)?</p>
  
  <p>Let's say we have two tables:</p>
  
  <pre>
  CATEGORIES      CATEG_PARENTS
  id              idc  | idparent
  --              ----------------
  1               2      1
  2               2      20
  5               5      2
  8               8      5
  20              20     1
  22              22     8
  30              22     20
  31              30     20
  36              31     22
                  31     30
                  36     31
  </pre>
  
  <p>These are two possible representations:</p>
  
  <p><a href="https://i.stack.imgur.com/oXd3R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oXd3R.png" alt="alt text"></a><br>
  <sub>(source: <a href="http://nebm.ist.utl.pt/~glopes/img/graphso.png" rel="nofollow noreferrer">glopes at nebm.ist.utl.pt</a>)</sub>  </p>
  
  <p><a href="https://i.stack.imgur.com/jBgYG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jBgYG.png" alt="alt text"></a><br>
  <sub>(source: <a href="http://nebm.ist.utl.pt/~glopes/img/graphso2.png" rel="nofollow noreferrer">glopes at nebm.ist.utl.pt</a>)</sub>  </p>
  
  <p>This is the output I desire:</p>
  
  <pre>
  ids
  -------------------
  "{1,20,22,31}"
  "{1,20,2,5,8,22,31}"
  "{1,20,30,31}"
  "{1,2,5,8,22,31}"
  </pre>
  
  <p>One path per line, written as an integer array.</p>
  
  <p>(I'm going to write the answer I came up with, but I'll accept any that's simpler, if any)</p>