title: Check Whether Given Degrees Vertices Represent Graph Tree
signature: function check_whether_given_degrees_vertices_represent_graph_tree(degree, 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.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(degree, n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(degree, n) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({2, 3, 1, 1, 1}, 5, true)
      print(string.format("TEST-0...%s",result))
  
      result = driver({2, 2, 1, 1, 2}, 5, true)
      print(string.format("TEST-1...%s",result))
  
      result = driver({2, 2, 1, 1, 1}, 5, false)
      print(string.format("TEST-2...%s",result))
  
      result = driver({0, 0, 0, 3, 3, 4}, 6, true)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-10, 12, 2}, 3, true)
      print(string.format("TEST-4...%s",result))
  
      result = driver({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)
      print(string.format("TEST-5...%s",result))
  
      result = driver({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)
      print(string.format("TEST-6...%s",result))
  
      result = driver({66, -96, -14, 74, -20}, 4, false)
      print(string.format("TEST-7...%s",result))
  
      result = driver({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)
      print(string.format("TEST-8...%s",result))
  
      result = driver({97, 73, 87, 45, 64, 30, 53, 50, 62, 42, 28, 58, 31, 90}, 10, false)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
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.extension: lua
question_info.entry_fn_name: check_whether_given_degrees_vertices_represent_graph_tree
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__