optimize adjacency list writing