EIUDFS1 - DFS Directed Graph

Xem dạng PDF

Gửi bài giải

Điểm: 1,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: stdin
Output: stdout

Nguồn bài:
Hà Minh Ngọc
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Given a directed graph, print the order of visiting vertex using Deep-First Search algorithm from vertex ~0~ and smallest vertex is prioritized than other vertices.

Input

  • The first line consists of two positive integers, the number ~n~ vertices ~(n\leq 10^5)~ and the number of edges m ~(m \leq 2 \times 10^5)~.
  • Then there are ~m~ lines, each containing two integers ~u~ and ~v~ representing an edge from ~u~ to ~v~.~(u,v < 10^5)~.

Output

  • Print the list of vertex separated by spaces.

Example Input

4 4
0 3
3 2
1 0
0 1

Example Output

0 1 3 2

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.