GHOSTS - Ghosts having fun
Ghost are living in big castle with K rooms.
As they have around few hundred years and very tired, they decided to buy teleports. Every teleport can work only in one way ( to prevent collision ). Ghosts have decided which teleports they want to build and in which order they should be built.
King of ghosts, Bob, asked you to check list of teleports and decide which of them do not build. He don't want ghosts having fun in infinite ride with teleports.
In first line - number K<=1000, amount of rooms in castle.
In next line - number T<=300000 of teleports.
In next T lines a,b<=K
Rooms are numbered 1..K
Print teleports which should not be built. End test case with 0 0
3 13 2
@codesmiler you can't print 1 2 instead of 3 1 because you've got 1 2 earlier till then there was no 3 1 ,so after putting teleport 1 2 you got 3 1 so remove that 3 1 and answer should be in order indeed
why can't we remove 1 2,3 2
O(T*K^2) giving TLE :/Last edit: 2016-06-17 15:18:58
Finally accepted after getting many RTE :) very silly mistake
What happens if we print all the edges ? Still there would be no infinite loops in the graph .....
OK, it seems that after ages I see a bug in my code.
Well, if I am right ( I am still coding ), there is small trick... But as I see some people are asking, you have to output teleports in the same order you input them, just with 99% you output less.