```
public class Solution {
public boolean validTree(int n, int[][] edges) {
Set<Integer> set = new HashSet<>();
for (int[] edge : edges) {
if (!set.add(edge[0])) {
set.remove(edge[0]);
}
if (!set.add(edge[1])) {
set.remove(edge[1]);
}
if (set.size() == 0) {
return false;
}
}
return edges.length == n - 1;
}
}
```

8

[[1,2],[2,3],[3,4],[4,5],[5,6],[6,3], [6,1]]

Your answer

true

Expected answer

false