depth-first-search

    1热度

    1回答

    我想要到达此树的节点Y,但是此代码遍历整棵树。我应该做些什么来实现我的目标?如何在遍历的每一步显示走过的路径?我使用深度优先搜索。 感谢您的任何帮助。 class Graph { int V; // No. of vertices list<int> *adj; void DFSUtil(int v, bool visited[]); public: Graph(int V); v

    -2热度

    1回答

    我很困惑的线res.add(new ArrayList<Integer>(temp));。你能告诉我为什么我错用了res.add(temp)? public void dfs(int[] nums, int index, List<List<Integer>> res, List<Integer> temp) { res.add(new ArrayList<Integer>(temp))

    1热度

    2回答

    我有以下的Node对象 class Node(object): def __init__(parent=None, data) self.__parent = parent self.__data = data self.__children = [] # parent and data properties getters and set

    0热度

    1回答

    我对这个例子有些困惑。通常,图表的深度优先搜索按字母顺序/递增顺序完成。 (是否有可能从顶点B开始第三次访问顶点M)。是否有人可以给我讲解一下:

    0热度

    2回答

    有人能指出我的代码出了什么问题吗?从我观察到的情况来看,返回根目录无法正常工作。 private Node find(String name, Node root) { if (root != null) { if (root.name.equals(name)){ System.out.println(root.name); re

    2热度

    1回答

    我被赋予作为一个任务来解决迷宫,使用球拍表示为一个隐式图。我想这样做,使用深度优先搜索和递归正在一路攀升到它必须返回,并按照不同的路径,在这里我得到的错误: application: not a procedure; expected a procedure that can be applied to arguments given: #<void> arguments..

    1热度

    1回答

    我正在用DFS算法处理16 * 16数独问题。 Java代码的样子: public class dfs { public boolean dfs(int[][] puzzle,int i,int j){ if(i==15&&j>=16) return true; if(j==16){ //System.out.println(String.valu

    0热度

    1回答

    回溯我想写一个DFS搜索以下加权图: 0 1. 2. 3 4. 5. 6. 7. 8. 0: 0.0, 0.68, 78.926, 6.205, 6.707, 48.45, 0.59, 0.704, 0.978, 1: 1.47, 0.0, 116.021, 9.129, 9.869, 71.284, 0.869, 1.09, 1.44, 2: 0.012, 0.0086,

    1热度

    1回答

    最近我遇到一个问题叫Gravity Tree 我无法自己解决,所以我检查了editorial。作者的解决方案是在顶点一次dfs并形成一个段树,其中每个节点包含从顶点到中心的距离。然后他提到了第二个dfs(我不知道这是做什么,我尝试打印他的数据结构,但他们完全没有意义,不知道他究竟想要做什么)。他写的语言太难以掌握了。我知道什么是细分树,dfs,懒散的传播。但是我无法围绕这个解决方案。不知道解决方案

    0热度

    1回答

    我正在尝试在Hackerrank中解决这个graph problem,这是迄今为止我所知道的。我正在使用Python字典来表示图形,并让我的DFS函数返回它所遍历的连接组件的长度。我的代码通过了第一个测试用例,但给我一些其他测试用例的运行时错误。这是一个优化问题吗?如果是这样,我应该尝试优化哪部分代码?或者我应该尝试完全不同的方法? import sys n = input() # Graph