# グラフgに対するトポロジカルソート topologicalSort(g): Queue que # 入次数を計算 for u ← 0 to g.N - 1: for v in g.adjLists[u]: deg[v]++ for v ← 0 to g.N - 1: if deg[v] = 0: que.enqueue(v) t ← 1 while not que.empty(): u ← que.dequeue() order[u] ← t++ for v in g.adjLists[u]: deg[v]-- if deg[v] = 0: q.enqueue(v)