98. 所有可达路径 def allPathsSourceTarget(graph,n): ans = list() stk = list() def dfs(x: int): if x == n: ans.append(stk[:]) return for y in graph[x]: stk.append(y) dfs(y) stk.pop() stk.append(1) dfs(1) return ans if len(ans) !=0 else -1 n,m = list(map(int,input().split())) import collections graph = collections.defaultdict(list) for i in range(m): path = list(map(int,input().split())) graph[path[0]].append(path[1]) paths = allPathsSourceTarget(graph,n) if paths == -1: print(-1) else: for path in paths: print(' '.join(map(str, path)))