title: Check Whether Given Degrees Vertices Represent Graph Tree
signature: bool checkWhetherGivenDegreesVerticesRepresentGraphTree(vector<int> degree, int n) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(bool actual, bool expected){
      return actual == expected;
  }
  
  string driver(vector<int> degree, int n, bool expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(degree, n), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver({2, 3, 1, 1, 1}, 5, true); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({2, 2, 1, 1, 2}, 5, true); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({2, 2, 1, 1, 1}, 5, false); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 3, 3, 4}, 6, true); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-10, 12, 2}, 3, true); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      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); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      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); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({66, -96, -14, 74, -20}, 4, false); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      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); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({97, 73, 87, 45, 64, 30, 53, 50, 62, 42, 28, 58, 31, 90}, 10, false); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
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 );
  }