I am solving a problem for finding the size of the vertex cover for a given graph. Below is the test case for which I am not able to interpret what should be the output:
1 4
1 5
1 2
4 1
2 4
3 4
5 2
1 3
These are the edges of an undirected graph consisting of 5 vertices and 8 edges According to my understanding of minimum vertex cover the output should be either: {1,2,4} or {1,4,5} but when I am executing this test case on https://www.codingninjas.com/codestudio/problems/vertex-cover-problem_1081481?leftPanelTab=0 It is giving out that size of the minimum vertex cover set is 5 and when I execute on https://www.geeksforgeeks.org/vertex-cover-problem-set-1-introduction-approximate-algorithm-2/ It is telling me that it should be 4. Can anyone confirm me that whether I am interpreting this question correctly or not?
I can confirm that the answer for this test case should indeed be 3. {1, 2, 4} and {1, 4, 5} are vertex covers of the graph; all edges are covered. It is also minimum because there are no solutions with 2 vertexes (checked by hand and by code).
See this code snippet for the minimum vertex cover:
I have tried to make the code as intuitive as possible, as well as add comments in order to make the meaning behind each line of code clearer.
Texting against this input, which is the one you provided (note that for the first line,
4, 8
means there are 4 nodes and 8 edges):The output is:
This should be a correct output.