Set the A vertex as the starting point, and find the B vertex with depth-first search (DFS), width-first search (BFS), etc.
Google the graph search algorithm and study it~
(A tree is a type of graph.)
https://gmlwjd9405.github.io/2018/08/13/data-structure-graph.html
© 2024 OneMinuteCode. All rights reserved.