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.
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.