28 lines
432 B
Python
28 lines
432 B
Python
import sys
|
|
from collections import deque
|
|
|
|
N, M = map(int, input().split())
|
|
|
|
arr=[[] * N for i in range(N)]
|
|
visited = [False] * (N+1)
|
|
maxarr = [0] * (N+1)
|
|
graph = dict()
|
|
|
|
for i in range(M):
|
|
A, B = map(int, input().split())
|
|
graph[A] = B
|
|
|
|
def DFS(graph, start):
|
|
visited.append(start)
|
|
for node in graph[start]:
|
|
if node not in visited:
|
|
DFS(graph, node, visited)
|
|
return visited
|
|
|
|
DFS(graph, 1)
|
|
|
|
|
|
|
|
|
|
|