已知图中的两个结点的指针DirectedGraphNode* a和DirectedGraphNode* b(请不要在意数据类型,图是有向图),判断两点间是否存在一条路径并返回bool值,代表是否存在(a到b或b到a)。
加载中...
import java.util.*; /* public class UndirectedGraphNode { int label = 0; UndirectedGraphNode left = null; UndirectedGraphNode right = null; ArrayList
neighbors = new ArrayList
(); public UndirectedGraphNode(int label) { this.label = label; } }*/ public class Path { public boolean checkPath(UndirectedGraphNode a, UndirectedGraphNode b) { // write code here } }
/* struct UndirectedGraphNode { int label; vector
neighbors; UndirectedGraphNode(int x) : label(x) {} };*/ class Path { public: bool checkPath(UndirectedGraphNode* a, UndirectedGraphNode* b) { // write code here } };
# -*- coding:utf-8 -*- # class UndirectedGraphNode: # def __init__(self, x): # self.label = x # self.neighbors = [] class Path: def checkPath(self, a, b): # write code here
/* public class UndirectedGraphNode { public int label; public IList
neighbors; public UndirectedGraphNode (int x) { label = x; neighbors = new List
(); } }*/ class Path { public bool checkPath(UndirectedGraphNode a, UndirectedGraphNode b) { // write code here } }