← Back to topics
Topic

z-birthday-party

t
thocevar
I need a hint for this task, please.

I'm using stl map for mapping names to ids. Then I create a cycle for every table, flood the graph and count the number of components.
It times out after first two test cases. The slow part are name-id lookup, but the solution should be O(n*log n), unless I messed up somewhere in the code.

I've managed to squeeze out 3 test cases with disjoint-sets but both solutons are equally slow.

Edit:
I've tuned the solution to pass 6 cases with hashing for name-id lookup.
Time-limit seems really tight.
t
thocevar
anyone, please? :)
m
marveringius
instead of using map to look up everytime, first change the names for numbers, and then use a matrix with two dimensions to find the components...
m
marveringius
I didn't test this idea but I think it can work.. I'm waiting answers, ok? If you succeeded doing that, please return here to say that you got it, please..
Thank you.. ;)
t
thocevar
"I've tuned the solution to pass 6 cases with hashing for name-id lookup"

I've already tried it, didn't pass. Or perhaps I was just a bit sloppy when I implemented it.