title: Check Whether Given Degrees Vertices Represent Graph Tree
signature: class Solution {
  
      public Boolean checkWhetherGivenDegreesVerticesRepresentGraphTree(ArrayList<Integer> degree, Integer n) {
source_py: def check_whether_given_degrees_vertices_represent_graph_tree(degree, n):
      deg_sum = sum(degree)
      if ((2 * (n - 1)) == deg_sum):
          return True
      else:
          return False
source_cpp: bool check_whether_given_degrees_vertices_represent_graph_tree(vector<int> degree, int n) {
    int deg_sum = 0;
    for ( int i = 0;
    i < n;
    i ++ ) deg_sum += degree [ i ];
    return ( 2 * ( n - 1 ) == deg_sum );
  }
question_info.extension: java
question_info.entry_fn_name: checkWhetherGivenDegreesVerticesRepresentGraphTree
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": true, "inputs": {"degree": [2, 3, 1, 1, 1], "n": 5}}, {"idx": 1, "outputs": true, "inputs": {"degree": [2, 2, 1, 1, 2], "n": 5}}, {"idx": 2, "outputs": false, "inputs": {"degree": [2, 2, 1, 1, 1], "n": 5}}, {"idx": 3, "outputs": true, "inputs": {"degree": [0, 0, 0, 3, 3, 4], "n": 6}}, {"idx": 4, "outputs": true, "inputs": {"degree": [-10, 12, 2], "n": 3}}, {"idx": 5, "outputs": false, "inputs": {"degree": [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0], "n": 19}}, {"idx": 6, "outputs": false, "inputs": {"degree": [1, 6, 10, 13, 15, 17, 18, 23, 26, 28, 30, 32, 32, 33, 36, 39, 39, 41, 43, 50, 50, 51, 53, 54, 59, 59, 63, 63, 63, 66, 66, 71, 71, 74, 78, 89, 89, 93], "n": 30}}, {"idx": 7, "outputs": false, "inputs": {"degree": [66, -96, -14, 74, -20], "n": 4}}, {"idx": 8, "outputs": false, "inputs": {"degree": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 31}}, {"idx": 9, "outputs": false, "inputs": {"degree": [97, 73, 87, 45, 64, 30, 53, 50, 62, 42, 28, 58, 31, 90], "n": 10}}]
question_info.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(ArrayList<Integer> degree, Integer n, Boolean expected){
          try{
              Driver driver = new Driver();
              if (driver.run(degree, n,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(new ArrayList<>(Arrays.asList(2, 3, 1, 1, 1)), 5, true);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(2, 2, 1, 1, 2)), 5, true);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(2, 2, 1, 1, 1)), 5, false);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 3, 3, 4)), 6, true);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-10, 12, 2)), 3, true);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0)), 19, false);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(1, 6, 10, 13, 15, 17, 18, 23, 26, 28, 30, 32, 32, 33, 36, 39, 39, 41, 43, 50, 50, 51, 53, 54, 59, 59, 63, 63, 63, 66, 66, 71, 71, 74, 78, 89, 89, 93)), 30, false);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(66, -96, -14, 74, -20)), 4, false);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 31, false);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(97, 73, 87, 45, 64, 30, 53, 50, 62, 42, 28, 58, 31, 90)), 10, false);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> degree, Integer n, Boolean expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(degree, n),expected);
      }
      
      public boolean validateSolution(Boolean actual, Boolean expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__