classSolution { public: int n = 200005; vector<int> father = vector<int>(n, 0); voidinit(){ for (int i = 0; i < father.size(); i++) { father[i] = i; } } voidjoin(int u, int v){ u = find(u); v = find(v); if (u == v) return; father[v] = u; } intfind(int u){ if (u == father[u]) return u; // else return find(father[u]); else { father[u] = find(father[u]); return father[u]; } } boolisSame(int u, int v){ u = find(u); v = find(v); return u == v; } boolvalidPath(int n, vector<vector<int>>& edges, int source, int destination){ init(); for (vector<int>& item : edges) { join(item[0], item[1]); } returnisSame(source, destination); } };