Hello here I know that algorithm implementation in N*log(M). N- number of vertices, M- number of edges. I have solved plenty of problems about it on various websites such as: Codeforces, Hackerrank, Codechef and so on. If you wish you can check my activity, below is mentioned my username. For sure I can solve your problem easily.
username: vaxo9910