http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2141&cid=1186

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<queue>
using namespace std ;
int map[][] ;
int vis[] ;
int ans[] ;
int i,j ,u,v;
int dingdian,n,bian ,h;
int mark=;
queue<int>q ;
void bfs(int h)
{
memset(ans,,sizeof(ans)) ;
memset(vis,,sizeof(vis)) ;
q.push(h) ;
vis[h] = ;
while(!q.empty())
{
int t = q.front() ;
q.pop() ;
if(mark)
{
printf("%d",t);
mark=;
}
else printf(" %d",t);
for(i = ; i < dingdian ; i++)
{
if(!vis[i]&&map[t][i])
{
q.push(i) ;
vis[i] = ;
}
}
}
}
int main()
{
cin>>n ;
queue<int>q ;
memset(map,,sizeof(map)) ;
for(i = ; i <= n ; i++)
{
scanf("%d%d%d",&dingdian,&bian,&h) ;
int j ;
for(j = ; j <bian ; j++)
{
scanf("%d%d",&u,&v) ; map[u][v] = map[v][u] = ;
}
bfs(h) ;
cout<<endl ;
}
return ;
}

SDUT2141数据结构实验图论一:基于邻接矩阵的广度优先搜索遍历的更多相关文章

  1. SDUT 2141 【TEST】数据结构实验图论一:基于邻接矩阵的广度优先搜索遍历

    数据结构实验图论一:基于邻接矩阵的广度优先搜索遍历 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Discuss Problem ...

  2. 数据结构之 图论---基于邻接矩阵的广度优先搜索遍历(输出bfs遍历序列)

    数据结构实验图论一:基于邻接矩阵的广度优先搜索遍历 Time Limit: 1000MS Memory limit: 65536K 题目描述 给定一个无向连通图,顶点编号从0到n-1,用广度优先搜索( ...

  3. SDUT-2124_基于邻接矩阵的广度优先搜索遍历

    数据结构实验之图论一:基于邻接矩阵的广度优先搜索遍历 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 给定一个无向连通图 ...

  4. 数据结构实验之图论一:基于邻接矩阵的广度优先搜索遍历 (SDUT 2141)

    #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> ...

  5. 基于邻接矩阵的广度优先搜索遍历(BFS)

    题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2141&cid=1186 #include<stdio.h> #incl ...

  6. SDUT 2142 数据结构实验之图论二:基于邻接表的广度优先搜索遍历

    数据结构实验之图论二:基于邻接表的广度优先搜索遍历 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Descript ...

  7. SDUT2142数据结构实验之图论二:基于邻接表的广度优先搜索遍历

    http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2142&cid=1186 题目描述 给定一个无向连通图,顶点编号从0到n-1,用广度优先搜 ...

  8. 数据结构之 图论---连通分量的个数(dfs搜索)

    数据结构实验:连通分量个数 Time Limit: 1000MS Memory limit: 65536K 题目描述  在无向图中,如果从顶点vi到顶点vj有路径,则称vi和vj连通.如果图中任意两个 ...

  9. 基于邻接矩阵的深度优先搜索(DFS)

    题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2107&cid=1186 #include<stdio.h> #incl ...

随机推荐

  1. zedboard 构建嵌入式linux

    本文通过五部完成zedboard的嵌入式LINUX搭建,所谓磨刀不五砍材工嘛 1:系统环境搭建 要准备好交叉编译环境 见http://blog.csdn.net/xiabodan/article/de ...

  2. Linux man 用法小结(Linux指令学习笔记)

    今天买了一本<<Linux命令行与shell脚本编程大全>>,想利用暑假放假的时间系统的学习一下 Linux的shell脚本.今天看了一下书,才发现我之前学习,把Linux s ...

  3. jdk、maven配置

    JDK环境变量配置1.新建系统变量 1)变量名:JAVA_HOME 变量值:C:\Program Files\Java\jdk1.7.0_15 2)变量名:CLASSPATH 变量值:.;%JAVA_ ...

  4. linq 日常关键字使用

    1.from var scoreQuery = from student in students from score in student.Scores where score > 90 se ...

  5. Unity学习笔记(4):依赖注入

    Unity具体实现依赖注入包含构造函数注入.属性注入.方法注入,所谓注入相当赋值,下面一个一个来介绍 1:构造函数注入 1.1当类有多个构造函数时,可以通过InjectionConstructor特性 ...

  6. require.js入门指南(二)

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  7. 无法打开物理文件xxx.mdf 操作系统错误 5:“5(拒绝访问。)” (Microsoft SQL Server,错误: 5120) 的解决方法

    问题描述:在附加数据库到sql server时,附加不上,出现如下图所示的错误 解决方法:找到xxx.mdf和xxx_log.ldf文件, 点击“右键”->“属性”->"安全&q ...

  8. 第六周 E题 期望.....

    Description Given a dice with n sides, you have to find the expected number of times you have to thr ...

  9. atomic_read

    static inline int atomic_read(const atomic_t *v) { return (*(volatile int *)&(v)->counter); } ...

  10. (转)MapReduce二次排序

    一.概述 MapReduce框架对处理结果的输出会根据key值进行默认的排序,这个默认排序可以满足一部分需求,但是也是十分有限的.在我们实际的需求当中,往往有要对reduce输出结果进行二次排序的需求 ...