Find a path on the graph

Simply speaking , It's division from the starting point , Mark every point you pass , Back off when you find the end , Called deep search .

Judging from V Can we get to the end

Define a function , Judge if it's the end you want , If so , It's over , No. , Just walk over and mark , For other adjacent nodes , If that's the point, it's over , If not, continue .

From here on, the content mainly comes from Guo Wei of Peking University , I study as a note
bool Dfs(V) { if( V End point ） return true; if( V Old point ) return false; take V Mark as old point ;
Right and V Every adjacent node U{ if( Dfs(U) == true) return true; } return false; } int main() {
Mark all points as new ; Starting point = 1 End = 8 cout << Dfs( Starting point ）; }
If you need to record the path ： Add path[depth];
Node path[MAX_LEN]; //MAX_LEN Just take the total number of nodes int depth; bool Dfs(V) { if( V End point ）{ path[
depth] = V; return true; } if( V Old point ) return false; take V Mark as old point ; path[depth]=V; ++
depth; 1516 Right and V Every adjacent node U { if( Dfs(U) == true) return true; } --depth; return
false; }
Representation of Graphs

Using a two-dimensional array G Storage map ,G[i][j] Representation node i Node j of
Situation on the border ( If there is no edge , Edge direction , Weight size, etc )

Technology
Daily Recommendation
views 26
views 2