TLE in CF educational round 78 problem D

can somebody explain why am i getting tle in for this solution of problem D in cf educational round 78
my solution complexity is nlogn .
link to problem:

i used the idea of sweep line algorithm to connect the segments till it reaches n-1 edges.
after that i check for cyclicity of the graph.

in sweep line algo:
1)i process througth all the end points in ascending order.
2)if a segment is starting at this point i am making edges between the active segments which has finishing point less than the current segment and the current segment and i am adding the current segment to active segments.
3) if a segment is ending at this point i am just deleting it from active segments.

Your edge adding procedure is O(n^2). Try to improve it.

I stop after i add n edges so it will not be O(n^2)