<｜begin▁of▁sentence｜>### Instruction:
Given a tree graph where each non-leaf vertex has 2 children and there are 5 vertices in total, create a depth-first search (DFS) iterator starting from the root vertex (0). How would you collect all vertices encountered during the DFS and represent them in a JSON object?
### Response:
from igraph import Graph
import json

g = Graph.Tree(5, 2)  # Creating a sample tree graph with 5 vertices

dfs_iter = g.dfsiter(0, mode='ALL')  # Creating a DFS iterator starting at vertex 0

# Collecting all vertices encountered during the depth-first search
vertices_dfs = [v.index for v in dfs_iter]

# Convert the list to JSON
vertices_json = json.dumps({'vertices_dfs': vertices_dfs})
print(vertices_json)
<|EOT|>
