package medium;

import java.util.Arrays;

/**
 * Created by fishercoder1534 on 9/29/16.
 */
public class GraphValidTree {

    public boolean validTree(int n, int[][] edges){
        int[] nums = new int[n];
        Arrays.fill(nums, -1);

        for(int i = 0; i < edges.length; i++){
            int x = find(nums, edges[i][0]);
            int y = find(nums, edges[i][1]);

            if(x == y) return false;

            //union
            nums[x] = y;
        }

        return edges.length == n-1;
    }

    int find(int[] nums, int i){
        if(nums[i] == -1) return i;
        return find(nums, nums[i]);
    }
}

@@ -214,29 +214,45 @@
     
-Arrays.fill(nums, -1)
+for(int i =0; i %3C n; i++) nums%5Bi%5D = i
 ;%0A%0A 
@@ -580,18 +580,17 @@
 s%5Bi%5D == 
--1
+i
 ) return

use index as its ID