code: public static boolean isDepTree(int[] parents, boolean isProjective, boolean isSingleHeaded) {
          // Check that every token has some head. (Note that the parents array encoding ensures we
          // can't have multiple heads per token.)
          int emptyCount = ParentsArray.countChildrenOf(parents, ParentsArray.EMPTY_POSITION);
          if (emptyCount != 0) {
              return false;
          }
          // Check that there is exactly one node with the WALL as its parent
          int wallCount = ParentsArray.countChildrenOf(parents, ParentsArray.WALL_POSITION);
          if (isSingleHeaded && wallCount != 1) {
              return false;
          } else if (wallCount < 1) {
              return false;
          }
  
          // Check that there are no cyles
          if (!ParentsArray.isConnectedAndAcyclic(parents)) {
              return false;
          }
  
          // Check for projectivity if necessary
          if (isProjective) {
              if (!ParentsArray.isProjective(parents)) {
                  return false;
              }
          }
          // Is a valid dependency tree.
          return true;
      }
docs: Returns whether this is a valid depedency tree: a directed acyclic graph
  with a single root which covers all the tokens.