The mechanisms of impurity-impurity and impurity-matrix interactions in B/N-doped graphene