本文主要是介绍dfs + 链式向前星,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
用链式向前星存图,用bfs求出起点到终点的最小步数
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;struct node
{int to,next;int w;
}edge[100];
int head[100];
int vis[100];
int total = 1;
void AddEdge(int u, int v, int w)
{edge[total].to = v;edge[total].w = w;edge[total].next = head[u];head[u] = total ++;
}
int Min = 9999;
int time = 0;void dfs(int start, int end, int step)
{//cout << "start=" << start << endl;//cout << "end=" << end << endl; if(start == end) {// cout << (++time) << " " ;// cout << "step=" << step << endl;;if(Min > step){Min = step;}return ;}for(int i = head[start]; i != -1; i = edge[i].next){int to = edge[i].to;if(!vis[to
这篇关于dfs + 链式向前星的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!