Time and Energy Complexity of Distributed Computation of a Class of Functions in Wireless Sensor Networks