This problem!
1) If you are getting Wrong Answer :
=> Check for the condition :
looping on the same node(1 1) ,(2 2)....
Example : 3
3
1 1
2 2
1 2
2) If you are getting Time Limit Exceeded :
=> Do-not add edge when there already exists a path between two nodes.
Example : if input is (a b) then there is no need to add edge if you already have path from a to b ( a~>b) as it adds nothing to the given graph.
1) If you are getting Wrong Answer :
=> Check for the condition :
looping on the same node(1 1) ,(2 2)....
Example : 3
3
1 1
2 2
1 2
2) If you are getting Time Limit Exceeded :
=> Do-not add edge when there already exists a path between two nodes.
Example : if input is (a b) then there is no need to add edge if you already have path from a to b ( a~>b) as it adds nothing to the given graph.