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

Long leg

Time limit: 1000 ms
Memory limit: 256 MB
For an undirected, unweighted graph with $n$ vertices and $m$ edges, you need to find the shortest path from vertex $1$ to vertex $n$ such that at each step, you are allowed to traverse exactly $k$ edges, no more and no less. What is the minimum distance from vertex $1$ to vertex $n$? ### Input - The first line contains three integers $n$, $m$, and $k$. - The next $m$ lines each contain two integers $u$ and $v$, representing an edge between vertices $u$ and $v$. ### Output - Print the length of the shortest path from vertex $1$ to vertex $n$. Print `-1` if no path exists. ### Constraints - $1 \le n,m \le 10^5$. - $1 \le k \le 10$. - $1 \le u, v \le n$. ### Example Input: ``` 3 3 2 1 2 2 3 1 3 ``` Output: ``` 1 ```
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 1600
Solution (1) Solution