GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — LeetCode/BFS/505.The-Maze-II at master · wisdompeak/LeetCode

Expand file tree

/

505.The-Maze-II

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

505.The-Maze-II

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
505.The-Maze-II.cpp
505.The-Maze-II.cpp
 
 
Readme.md
Readme.md
 
 

Readme.md

505.The-Maze-II

本题中从某点朝四个方向走的路径权重不同,所以本题不适合用常规的BFS求解最短路径。此题是适用标准Dijkstra(BFS+PQ)算法的模板题。

Dijkstra算法的整体框架类似于BFS,将起点放入一个队列中。每个回合从队首弹出一个位置,然后将这个位置邻接的四个位置压入队列,直至我们弹出终点。不同之处在于我们使用的是一个优先队列,里面存放给的是行走状态的两个信息{steps, position},并且按照steps从小到大排序。如果某个position第一次从队列中弹出,那么根据贪心思想,意味着从起点到达这个position的最短路径就是steps。

注意,已经被确认最短路径的position就再不需要放入队列中。

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.