I’m trying to solve SPOJ PT07X - Vertex Cover (https://www.spoj.com/problems/PT07X/). I tried implementing a greedy approach based on the following,
- For each leaf of the tree, select its parent (i.e. its parent is in minimum vertex cover).
- For each internal node, if any of its children is not selected, then select this node.
However, I’m getting WA on SPOJ. Here’s my solution for the same. (https://ideone.com/Z3VD2L)
Kindly, let me know where I’m going wrong. Thank you.