SDUT 3361 数据结构实验之图论四:迷宫探索
数据结构实验之图论四:迷宫探索
Problem Description
Input
连续T组数据输入,每组数据第一行给出三个正整数,分别表示地下迷宫的结点数N(1 < N <= 1000)、边数M(M <= 3000)和起始结点编号S,随后M行对应M条边,每行给出一对正整数,表示一条边相关联的两个顶点的编号。
Output
若可以点亮所有结点的灯,则输出从S开始并以S结束的序列,序列中相邻的顶点一定有边,否则只输出部分点亮的灯的结点序列,最后输出0,表示此迷宫不是连通图。
访问顶点时约定以编号小的结点优先的次序访问,点亮所有可以点亮的灯后,以原路返回的方式回到起点。
Example Input
1
6 8 1
1 2
2 3
3 4
4 5
5 6
6 4
3 6
1 5
Example Output
1 2 3 4 5 6 5 4 3 2 1
DQE:
#include <iostream>
#include <cstdio>
using namespace std; #define MVN 1010 //注意数组尺寸 typedef struct AdjMatrix
{
int w;
char *info;
}AM; typedef struct MGraph
{
int vex[MVN];
AM arc[MVN][MVN];
int vexn,arcn;
int s;
}MG; void creat(MG &G)
{
int i,j,k;
for(i=;i<=G.vexn;i++)
for(j=;j<=G.vexn;j++)
G.arc[i][j].w=;
for(k=;k<=G.arcn;k++)
{
scanf("%d %d",&i,&j);
G.arc[i][j].w=G.arc[j][i].w=;
}
} int count; //计数变量
void DFS(MG &G,bool *f,int i)
{
f[i]=true;
count++;
if(i==G.s)
printf("%d",i);
else
printf(" %d",i);
int k;
for(k=;k<=G.vexn;k++)
if(G.arc[i][k].w==&&f[k]==false)
{
DFS(G,f,k); //从i到邻接点
printf(" %d",i); //回到i
}
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
MG G;
scanf("%d %d %d",&G.vexn,&G.arcn,&G.s);
creat(G);
bool visited[MVN]={false};
count=;
DFS(G,visited,G.s);
if(count!=G.vexn)
printf("");
printf("\n");
}
return ;
} /***************************************************
User name: ***
Result: Accepted
Take time: 0ms
Take Memory: 196KB
Submit time: 2016-11-18 21:18:16
****************************************************/
SDUT 3361 数据结构实验之图论四:迷宫探索的更多相关文章
- SDUT OJ 数据结构实验之图论四:迷宫探索
数据结构实验之图论四:迷宫探索 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...
- SDUT 3401 数据结构实验之排序四:寻找大富翁.!
数据结构实验之排序四:寻找大富翁 Time Limit: 150MS Memory Limit: 512KB Submit Statistic Problem Description 2015胡润全球 ...
- SDUT 3363 数据结构实验之图论七:驴友计划
数据结构实验之图论七:驴友计划 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 做为一个资深 ...
- SDUT OJ 数据结构实验之图论十:判断给定图是否存在合法拓扑序列
数据结构实验之图论十:判断给定图是否存在合法拓扑序列 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Prob ...
- SDUT OJ 数据结构实验之图论八:欧拉回路
数据结构实验之图论八:欧拉回路 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...
- SDUT OJ 数据结构实验之图论六:村村通公路(最小生成树)
数据结构实验之图论六:村村通公路 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...
- SDUT OJ 数据结构实验之图论五:从起始点到目标点的最短步数(BFS)
数据结构实验之图论五:从起始点到目标点的最短步数(BFS) Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss P ...
- SDUT OJ 数据结构实验之二叉树四:(先序中序)还原二叉树
数据结构实验之二叉树四:(先序中序)还原二叉树 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem ...
- SDUT OJ 数据结构实验之排序四:寻找大富翁
数据结构实验之排序四:寻找大富翁 Time Limit: 200 ms Memory Limit: 512 KiB Submit Statistic Discuss Problem Descripti ...
随机推荐
- uva1605 - Building for UN(构造法)
这道题构造出的结果很妙,考察思维能力.就两层,每层都n*n个格子,第一层第i行都放国家i,第二层第j列都放国家j. 需要注意的是ASCII中A至Z在a至z的前面(数字小),而且它们两组不挨着.所以需要 ...
- 3.18 CCProgressTo 进度计时器
CCProgressTimer * pross = CCProgressTimer::create(CCSprite::create("Icon.png")); pross-> ...
- SQL夯实基础(一):inner join、outer join和cross join的区别
一.数据构建 先建表,再说话 create database Test use Test create table A ( AID ,) primary key, name ), age int ) ...
- 如何重启mysql服务
window下: 在cmd中,键入services.msc,找到mysql,右键重启mysql
- php后台添加样式写法
和我们的光头后台讨论了样式的问题,总结一下 <span style="color:#6666cc;font-size: 12px" onclick="addwork ...
- 纯css 更改原生raiod与 checkbox的样式
原文地址: .checkbox input[type=checkbox], .checkbox-inline input[type=checkbox], .radio input[type=radio ...
- Python 设计一个简单的计算器
设计目标 实现加减乘除及拓号优先级解析 用户输入'1 - 2 * ( (6-3 +(-5/5)*(9-2*3/3 + 7/3*7/4*12 +10 * 5/5 )) - (-4*3)/ (12-3*2 ...
- 运行flask程序
Command Line Interface Installing Flask installs the flask script, a Click command line interface, i ...
- 蓝桥杯 算法训练 ALGO-115 和为T
算法训练 和为T 时间限制:1.0s 内存限制:256.0MB 问题描述 从一个大小为n的整数集中选取一些元素,使得它们的和等于给定的值T.每个元素限选一次,不能一个都不选. 输入格式 第一行 ...
- uboot中的TEXT_BASE
转载:http://blog.csdn.net/xxblinux/article/details/6281295 我们都知道U-BOOT分为两个阶段,第一阶段是(~/cpu/arm920t/start ...