Given a set of n dominoes, find the longest train that can be made by stacking them end to end. Similar to the first step of the domino game mexican-train.