117. 软件构建
from collections import deque, defaultdictdef main():n, m = map(int, input().split())umap = defaultdict(list)inn = [0] * n for _ in range(m):s, t = map(int, input().split())umap[s].append(t)inn[t] += 1 que = deque([i for i in range(n) if inn[i] == 0])res = []while(que):cur = que.popleft()res.append(cur)for file in umap[cur]:inn[file] -= 1 if inn[file] == 0:que.append(file)if len(res) == n:print(' '.join(map(str, res)))else:print(-1)if __name__ == '__main__':main()