Skip to content

Commit 018c49e

Browse files
author
alirezakhm
authored
Update minimum_vertex_cover_on_tree_O(V).cpp
1 parent 02e8a80 commit 018c49e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

graph/minimum_vertex_cover_on_tree_O(V).cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ int MVC(int v, int flag) { // Minimum Vertex Cover
1111
// Note: ‘Children’ is an Adjacency List that contains the directed version of the tree
1212
// (parent points to its children; but the children does not point to parents)
1313
ans = 0;
14-
for (int j = 0; j < (int)Children[v].size(); j++)
15-
ans += MVC(Children[v][j], 1);
14+
for(auto &u: Children[v]) ans += MVC(u, 1);
1615
}
16+
1717
else if (flag == 1) {
1818
ans = 1;
19-
for (int j = 0; j < (int)Children[v].size(); j++)
20-
ans += min(MVC(Children.[v][j], 1), MVC(Children[v][j], 0));
19+
for(auto &u: Children[v])
20+
ans += min(MVC(u, 1), MVC(u, 0));
2121
}
2222
return memo[v][flag] = ans;
2323
}

0 commit comments

Comments
 (0)