Help Please !

I have just recently started using C++ for writing codes. I wrote solution to Lost grph LSTGRPH Problem - CodeChef having same time complexity as that of accepted solutions, but i am getting a TLE. I want to know why is it so if somebody could go through my solution and explain CodeChef: Practical coding for everyone

you have used a map with pairs as key values… maps are queried and updated in O(logn), where n is the number of values “mapped”, and i think you are mapping a lot of keys in it, this extra complexity of logn (where n is quite large) might be slowing down your code …