finally nailed the grph problem