Add build_graph function to util.py
Use util.py for graph building