sdut 图的深度遍历
来源:互联网 发布:好听劲爆的网络dj歌曲 编辑:程序博客网 时间:2024/04/27 15:23
图的深度遍历
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic Discuss
Problem Description
请定一个无向图,顶点编号从0到n-1,用深度优先搜索(DFS),遍历并输出。遍历时,先遍历节点编号小的。
Input
输入第一行为整数n(0 < n < 100),表示数据的组数。 对于每组数据,第一行是两个整数k,m(0 < k < 100,0 < m < k*k),表示有m条边,k个顶点。 下面的m行,每行是空格隔开的两个整数u,v,表示一条连接u,v顶点的无向边。
Output
输出有n行,对应n组输出,每行为用空格隔开的k个整数,对应一组数据,表示DFS的遍历结果。
Example Input
14 40 10 20 32 3
Example Output
0 1 2 3
#include<iostream>#include<cstring>using namespace std;int map[100][100],path[10000],visit[10000]={0},l=1,n,m;void DFS(int st,int ed){/*if(st==ed){for(int i=0;i<l-1;++i)cout<<path[i]<<' ';cout<<path[l-1]<<endl;}*/visit[st]=1;//标记已经访问过 for(int i=0;i<n;++i){if(!visit[i]&&map[st][i]){cout<<' '<<i; DFS(i,n-1);//--l;//visit[i]=0;//记忆化搜索 }}}int main(){int t;cin>>t;while(t--){memset(visit,0,sizeof(visit));memset(map, 0, sizeof(map)); cin>>n>>m;for(int i=0;i<m;++i){int a,b;cin>>a>>b;map[a][b]=map[b][a]=1;}cout<<0;DFS(0,n-1);cout<<endl; }return 0;}
0 0
- sdut 图的深度遍历
- SDUT-图的深度遍历
- 图的深度遍历 SDUT 2107
- SDUT OJ 图的深度遍历
- SDUT 2107 图的深度遍历
- sdut oj2107 图的深度遍历(DFS)
- SDUT OJ 2107 图的深度遍历
- SDUT 2107 图的深度遍历
- [SDUT](2107) 图的深度遍历 ---DFS(图)
- SDUT 图的深度优先遍历(邻接矩阵表示)
- SDUT图的深度遍历之邻接表算法
- 图的深度遍历
- 图的深度遍历
- 图的深度遍历
- 图的深度遍历
- 图的深度遍历
- 图的深度遍历
- 图的深度遍历
- sdut 二叉排序树
- 新书通告
- Step-By-Step Guide To Create Physical Standby On Normal File System For ASM Primary using RMAN (文档 I
- C程序设计_知识回顾
- Creating a physical standby from ASM primary (文档 ID 787793.1)
- sdut 图的深度遍历
- python7--win10下python3.5安装scrapy
- 【0基础掌握安卓开发技术】
- 关于USB3.0的U盘正确用法
- Kerberos 认证原理笔记
- Mysql基准测试工具介绍
- kerberos认证原理---细致易懂
- geoip处理区分IP地理位置
- 系列博客 - 从开发员到企业架构师