Not getting any output

I am doing this question from codeforces…
https://codeforces.com/problemset/problem/129/B
This is my solution…
when i am running it on coding block ide… it is showing segmentation fault .But i am not able to find this.
https://ide.codingblocks.com/s/375150
Please look into this.
Thanks

hello @ashishnnnnn

u r iterating on map and at the same time u are deleting its entries.
thats why it is creating such issue.

follow this-> 
store degree of each nodes.
iterate while there is atleast 1 nodes with degree value 1.
        in each iteration find node whose degree is 1 .
        now reduce degree of nodes that is connect to current node by 1.
        
i would suggest to first solve topological sort using bfs and then u can solve this problem on ur own