Try this:
for (i in 1:100) {
if (is.nan(bfs$dist[i]) == FALSE) {
V(graph)$value[i] = 1 - V(graph)$value[i]
}
}
It basically just checks if a node is connected to the root node. If it is, its attribute value is changed to 1, and if it isn't, then its attribute value remains unchanged.