(G, ind=None, Q=[1])
| 140 | |
| 141 | |
| 142 | def topo(G, ind=None, Q=[1]): |
| 143 | if ind is None: |
| 144 | ind = [0] * (len(G) + 1) # SInce oth Index is ignored |
| 145 | for u in G: |
| 146 | for v in G[u]: |
| 147 | ind[v] += 1 |
| 148 | Q = deque() |
| 149 | for i in G: |
| 150 | if ind[i] == 0: |
| 151 | Q.append(i) |
| 152 | if len(Q) == 0: |
| 153 | return |
| 154 | v = Q.popleft() |
| 155 | print(v) |
| 156 | for w in G[v]: |
| 157 | ind[w] -= 1 |
| 158 | if ind[w] == 0: |
| 159 | Q.append(w) |
| 160 | topo(G, ind, Q) |
| 161 | |
| 162 | |
| 163 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected