We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2eb1d70 commit af916e2Copy full SHA for af916e2
1 file changed
C++/graph-valid-tree.cpp
@@ -1,4 +1,3 @@
1
-
2
// Time: O(|V| + |E|)
3
// Space: O(|V| + |E|)
4
@@ -33,6 +32,7 @@ class Solution {
33
32
const int i = q.front();
34
q.pop();
35
visited.emplace(i);
+ --n;
36
for (const auto& n : nodes[i].neighbors) {
37
if (n != nodes[i].parent) {
38
if (visited.find(n) != visited.end()) {
@@ -45,6 +45,6 @@ class Solution {
45
}
46
47
48
- return true;
+ return n == 0;
49
50
};
0 commit comments