Submit | All submissions | Best solutions | Back to list |
EIUBFS2 - BFS Undirected Graph |
Given an undirected graph, print all vertices of the tree. When there is more than one vertex connect to visiting vertices, prioritize to visit the smaller nodes first.
Input
The first line consists of two positive integers, the number of vertices n (0 <n <10^5) and the number of edges m (0 <m <2x10^5).
Then there are m lines, each containing two integers u and v (u, v <10^5), representing an edge connecting node u and node v.
Output
The list of vertices in the required order, separated by spaces.
Example
Input: 4 4 0 3 3 2 1 0 0 1
Output: 0 1 3 2
Added by: | Ha Minh Ngoc |
Date: | 2015-12-30 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG FSHARP GO JAVA JS-MONKEY NODEJS PHP PYTHON PYPY PYPY3 PYTHON3 RUBY SQLITE SWIFT VB.NET |