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/882.Reachable-Nodes-In-Subdivided-Graph at master · wisdompeak/LeetCode

Expand file tree

/

882.Reachable-Nodes-In-Subdivided-Graph

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

882.Reachable-Nodes-In-Subdivided-Graph

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
882.Reachable-Nodes-In-Subdivided-Graph_v1.cpp
882.Reachable-Nodes-In-Subdivided-Graph_v1.cpp
 
 
882.Reachable-Nodes-In-Subdivided-Graph_v2.cpp
882.Reachable-Nodes-In-Subdivided-Graph_v2.cpp
 
 
Readme.md
Readme.md
 
 

Readme.md

882.Reachable-Nodes-In-Subdivided-Graph

我们可以用Dijkstra求出从0点到任意原始节点i的最短距离(最少需要的moves),记为dist[i]。那么这个结果对于解题有什么帮助呢?

我们令edgeVisitedNodes[i][j]表示从i->j这条边,我们最多能再走几步(即访问多少个“细分点”)。因为总的maxMoves是固定的,我们自然希望到达i点时用的步数越少的话,那么我们在i->j这条边上能走的步数就越多。也就是说,我们能在i->j这条边上再走maxMoves-dist[i]步。注意,我们只考虑“细分点”而不考虑端点,因此这个数字不能超过这条边的cnt,即 VisitedSubNodes[i][j] = min(cnt, maxMoves - dist[i])

同理,我们也可以求出我们能在j->i这条边上再走多少步,即 VisitedSubNodes[i][j] = min(cnt, maxMoves - dist[i])。

有了以上的数据,我们再遍历所有的边i<->j,那么除了两个端点,我们能在这条边上访问到的“细分点”数目应该是min(VisitedSubNodes[i][j]+VisitedSubNodes[j][i], cnt). 我们另外从dist[i]统计所有能走到的端点。最终答案是两者之和。

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.