report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Finding the path - MarisaOJ: Marisa Online Judge

Finding the path

Time limit: 1000 ms
Memory limit: 256 MB
Given a undirected graph of $n$ vertices and $m$ edges. Find the shortest path from $1$ and $n$. It is guaranteed that $n$ is reachable from $1$. ### Input - The first line contains 2 integers $n, m$. - The next $m$ lines, each line contains 2 integers $u, v$, there is an edge between those vertices. ### Output - First print the length of the shortest path on one line. Then print the shortest path starting from $1$ and ending at $n$. If there are more than 1 solution, print any. ### Constraints - $1 \le n, m \le 10^5$. - $1 \le u, v \le 10^5$. ### Example Input: ``` 5 5 1 2 1 3 5 3 4 3 3 2 ``` Output: ``` 2 1 3 5 ```
BFS / DFS
Connected component
Shortest path
Finding the path
Path on binary matrix
Garden
Operations on number
Bipartite graph
Tom and Jerry
Festival 1
Bamboo Forest of the Lost
Radar
Festival 2
Go
Escape from... dolls
Long leg
Lexicographically smallest path
Graph coloring
Topic
Graph
Shortest path
Rating 800
Solution (0) Solution