A formula with its applications on the difference of Zagreb indices of graphs