boolean isConnected(int[][] graph, int[] node) {
    int start = 0;
    while (node[start] == 0) {
      start++;
    }
    boolean[] visited = new boolean[node.length];
    LinkedList<Integer> list = new LinkedList<Integer>();
    list.addLast(start);
    while (list.isEmpty() == false) {
      Integer first = list.removeFirst();
      visited[first] = true;
      for (int i = 0; i < node.length; i++) {
        if (!visited[i] && graph[i][first] > 0) {
          list.addLast(i);
        }
      }
    }
    for (int i = 0; i < node.length; i++) {
      if (node[i] > 0 && visited[i] == false) {
        return false;
      }
    }
    return true;
  }