-->
当前位置:首页 > 题库

PROGRAMMING:Sequence output of digraph

Luz5年前 (2021-05-10)题库479
Given the given digraph, then the output sequence of DFS and BFS, if for the same graph and the same initial node, then it should be output in order according to the size of the digital node. When visiting the subsequent node, it should visit the subsequent node in order according to the output order, and ensure the input in order in the topic input【 Test case: IOT project level 16 [Tian Xu]
###Input format:
First, enter the number of nodes N and the number of edges m in the graph. In the next M line, you will enter each edge in the format V1 V2, and the node number starts from 1(
###Output format:
The output sequence consists of two lines. The first line is DFS output sequence, and the second line is BFS output sequence. The format is "DFS (or BFS): sequence"
###Input example:
Here is a set of inputs. For example:
```in
6 6
1 2
1 6
2 4
2 5
4 3
6 3
```
###Output example:
The corresponding output is given here. For example:
```out
DFS: 1 2 4 3 5 6
BFS: 1 2 6 4 5 3
```







answer:If there is no answer, please comment