65,186
社区成员




/*
struct UndirectedGraphNode {
int label;
vector<struct UndirectedGraphNode *> neighbors;
UndirectedGraphNode(int x) : label(x) {}
};*/
class Path {
public:
bool checkPath(UndirectedGraphNode* a, UndirectedGraphNode* b) {
return check(a, b) || check(b, a);
}
bool check(UndirectedGraphNode* a, UndirectedGraphNode* b) {
if (a == NULL || b == NULL)
return false;
if (a == b)
return true;
map<UndirectedGraphNode*, bool> visited;
visited[a] = true;
for (int i = 0; i < a->neighbors.size(); i++)
{
if (a->neighbors[i] == b)
return true;
else
if (visited[a->neighbors[i]] == false)
return checkPath(a->neighbors[i], b);
}
return false;
}
};