DFS with States - Backtracking / Combinatorial Search

I am sorry to say that, but the example solution in Go isn’t really close to any guidelines accepted in said language and thus not really readable without frustration. Here is my solution

var res []string

func dfs(node Node, path []string){
    if len(node.children) == 0 {
        path = append(path, strconv.Itoa(node.val))
        res = append(res, strings.Join(path, "->"))
    }
   
    
    path = append(path, strconv.Itoa(node.val))
    for _, c := range node.children {
        dfs(c, path)
    }
}

func ternaryTreePaths(root Node) []string {
    dfs(root, nil)
    return res
}

or without nasty package level variable:

func dfs(node Node, path []string) []string{
    var res []string
    if len(node.children) == 0 {
        path = append(path, strconv.Itoa(node.val))
        return append(res, strings.Join(path, "->"))
    }
   
    
    path = append(path, strconv.Itoa(node.val))
    for _, c := range node.children {
        res = append(res,dfs(c, path)...)
    }
    return res
}

func ternaryTreePaths(root Node) []string {
    return dfs(root, nil)
}

is the time complexity O(V+E) as edges are visited twice. ?

Did the input data format change from the previous examples? Certainly the input in this example does not match that found in the cited link for serializing trees.

I would expect the shown tree to be represented as “1 2 3 x x x 4 x x x 5 x x x” based on the previous examples.

Something explaining the input would be helpful on each of the shown algorithms.