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 00206aa commit 8ec0968Copy full SHA for 8ec0968
1 file changed
C++/graph-valid-tree.cpp
@@ -20,13 +20,17 @@ class Solution {
20
nodes[edge.first].neighbors.emplace_back(edge.second);
21
nodes[edge.second].neighbors.emplace_back(edge.first);
22
}
23
+ if (nodes.size() != n) {
24
+ return false;
25
+ }
26
+
27
for (int i = 0; i < n; ++i) {
28
nodes[i].parent = -1;
29
30
31
unordered_set<int> visited;
32
queue<int> q;
- q.emplace(edges[0].first);
33
+ q.emplace(0);
34
while (!q.empty()) {
35
const int i = q.front();
36
q.pop();
0 commit comments