/******************************************************* * Copyright (C) 2015 Haotian Wu * * This file is the solution to the question: * https://www.hackerrank.com/challenges/even-tree * * Redistribution and use in source and binary forms are permitted. *******************************************************/ #include #include #include #include #include #include #include #include #include #include using namespace std; // We will use a greedy approach. Search bottom up. Whenever we see a subtree with even number of vertices, we decompose it. // It doesn't matter which node is the root. We just use node 1 as root. int ans = 0; int n,m; vector adj[101]; int work(int node, int parent) // This function counts how many nodes are there in its subtree { int sum = 1; // Count the node itself for (int i=0;i