code: function makeAcyclic(g) {
      var onStack = {};
      var visited = {};
  
      function dfs(u) {
        if (u in visited) {
          return;
        }
        visited[u] = true;
        onStack[u] = true;
        g.successors(u).forEach(function(v) {
          if (v in onStack) {
            g.addEdge(v, u);
            g.removeEdge(u, v);
          } else {
            dfs(v);
          }
        });
        delete onStack[u];
      }
  
      g.nodes().forEach(function(u) {
        dfs(u);
      });
    }
docs: /*
  This function modifies the supplied directed graph to make it acyclic by
  reversing edges that participate in cycles. This algorithm currently uses
  a basic DFS traversal.
  
  This algorithm does not preserve attributes.