BFS遍历图代码
来源:互联网 发布:linux 报文发送工具 编辑:程序博客网 时间:2024/06/06 15:30
#include<iostream>#include<vector>#include<queue>#include<cstring>#include<cstdio>using namespace std;const int maxn = 1005;vector<int> vec[maxn];queue<int> que;bool vis[maxn];int step[maxn];void BFS(int s){int i;int ele,ele1;que.push(s);vis[s] = true;while(!que.empty()){ele = que.front();que.pop();int len = vec[ele].size();//cout<<len<<endl;for(i=0;i<len;i++){ele1 = vec[ele][i];if(vis[ele1] == false){que.push(ele1);vis[ele1] = true;step[ele1] = step[ele] + 1;//cout<<step[ele1]<<endl;cout<<"ele1:"<<ele1<<" "<<"step:"<<step[ele1]<<endl;}}}}int main(){int m,n;int start;//freopen("1.txt","r",stdin);cin>>start; while(cin>>m>>n && m != 0 && n != 0){vec[m].push_back(n);vec[n].push_back(m);}memset(vis,false,sizeof(vis));memset(step,0,sizeof(step));BFS(start);//print_path();return 0;}
0 0
- BFS遍历图代码
- c++代码实现图的BFS遍历
- 图的遍历BFS
- BFS图的遍历
- 图的遍历-BFS
- 图的遍历BFS
- 图的dfs遍历和bfs遍历
- 图的遍历:DFS BFS
- 图的广度遍历(BFS)
- 图的遍历(DFS&BFS)
- 图的遍历[DFS][BFS]
- BFS遍历
- 广度优先遍历BFS的图算法
- 图的建立及BFS,DFS遍历
- DFS算法,BFS算法遍历图
- DFS BFS遍历图 矩阵存储
- DFS BFS遍历图 邻接表实现
- 图的遍历(BFS, DFS)源代码
- 笔记——*p++, (*p)++, *++p, ++*p的区别
- 实现简单登录,消息发送界面
- Rabbitmq-Java-Client重连和consumer恢复机制
- SessionID的本质
- ansible学习之--简单学习笔记3
- BFS遍历图代码
- MyEclipse2015 如何隐藏没用到的Server(MyEclipse Derby, MyEclipse Tomcat v7.0)
- 黑马程序员--Objective-C——面向对象
- hdu2710 筛选法求素数
- Android系统各版本及代号
- [leetcode] Remove Duplicates from Sorted Array II
- 你可能没注意的CSS单位
- PAT 数据结构 08-排序3. Talent and Virtue (25)
- 使用ObjectAnimator开发打开、关闭书本动画