#include <unordered_set>
/*
struct UndirectedGraphNode {
    int label;
    vector<struct UndirectedGraphNode *> neighbors;
    UndirectedGraphNode(int x) : label(x) {}
};*/

class Path {
public:
    bool checkPath(UndirectedGraphNode* a, UndirectedGraphNode* b) {
        auto cp = [](auto a, auto b) -> bool {
            queue<UndirectedGraphNode*> q{{a}};
            unordered_set<UndirectedGraphNode*> vis;
            while (not q.empty()) {
                auto t = q.front(); q.pop();
                if (b == t) return true;
                vis.insert(t);
                for (auto &v: t->neighbors) {
                    if (not vis.count(v)) q.push(v);
                }
            }
            return false;
        };
        return a==b or cp(a, b) or cp(b, a);
    }
};