writing script to build sparse graph