Better solution to hard problem?

Revision en1, by jeroenodb, 2021-08-18 16:09:25

I recently solved the problem Playlist on Kattis: https://open.kattis.com/problems/playlist. In brief the statement is:

Given a directed graph with $$$n \leq 100$$$ nodes and the outdegree of each node is less than 40. All the vertices are colored. Find a path of length 9 in the graph such that no pair of nodes in the path has the same color, and output this path. If there're multiple solutions, output any, output "fail" if there is no such path. The time limit is very big (12 seconds).

My solution involved meet-in-the-middle:

Split the path into a middle node and two paths of length 4 connected to this middle node. Now we first calculate for each node all the subsets of 4 colors such that there's exist a path of these four colors going into this node and going out of this node. This can be done by a DFS with extra state. The state is: The node we're on currently and the subset of colours we visited until know. A state can be extended by putting the colour of the current node in the subset and going to a neighbour of a color that isn't in our subset. We do this for the given graph, and the reverse graph. A simple bound of the number of states is

$$$\binom(100 4) \cdot 100 \approx 4 \cdot 10^8$$$

Because of all the hash tables and the huger number of states, my solution ran in 11 seconds.

Is there a simpler or faster solution? I couldn't find an editorial from the contest (Spotify Challenge 2011).

Tags meet-in-the-middle, #kattis, #graphs

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English jeroenodb 2021-08-18 16:31:30 781 (published)
en1 English jeroenodb 2021-08-18 16:09:25 1461 Initial revision (saved to drafts)