""" R. Tarjan, Enumeration of the elementary circuits of a directed graph, SIAM Journal on Computing, 2 (1973), pp. 211-216 procedure circuit_enumeration; begin procedure BACKTRACK(integer value v, logical result f); begin logical g; f := false; place v on point stack; mark(v) := true; place v on marked stack; for w in A(v) do if w # # This library is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. import sys if len(sys.argv) < 3: print "usage: %s num_vertices [v1,v2...]"%(sys.argv[0]) A = [[] for a in range(int(sys.argv[1]))] for edge in sys.argv[2:]: v1,v2 = edge.split(',', 1) A[int(v1)].append(int(v2)); def print_point_stack(): for p in point_stack: print p, print point_stack = list() marked = dict() marked_stack = list() def backtrack(v): f = False point_stack.append(v) marked[v] = True marked_stack.append(v) for w in A[v]: if w