- There should be exactly n-1 edges
- Use a counter to track if there are cycles and disconnections

```
public class Solution {
public boolean validTree(int n, int[][] edges) {
if(edges.length != n-1){
return false;
}
boolean[] map = new boolean[n];
Arrays.fill(map, false);
int cnt = 0;
for(int i = 0; i < edges.length; ++i){
int[] tmp = edges[i];
if(map[tmp[0]] && map[tmp[1]]){ // connect 2 known nodes, subtract 2 to remember it
cnt -= 2;
}
else if(!map[tmp[0]] && !map[tmp[1]]){ // connect 2 unknown nodes, add 1 to remember it
cnt += 1;
}
if(cnt < 0){ // connect 2 known nodes, not enough pairs of unknown nodes. There is cycle
return false;
}
map[tmp[0]] = true; // mark nodes to known
map[tmp[1]] = true; // mark nodes to known
}
return cnt == 0 || cnt == 1; // if cnt > 1, there are disconnections
}
}
```