Confusion about test case

In this problem, an example test case is as follows:

But I did some experimenting, and this tree would yield the same results:

Why is the one they give correct and the one I give wrong?


The second line of the input is the bfs, and the third line is the dfs. It looks like you swapped the two.

Ok, but even then, this graph would work:

So what makes this graph wrong and the one they give correct?

In the problem statement they say “generate the edge list of a simple, undirected, connected graph corresponding to these orders,” not the graph so I imagine if there are multiple solutions you are allowed to return the edge list corresponding to any one of them.

Yeah, you were right.