So I did some figuring out, and I'm pretty sure that it would take nine run-throughs of the secret quest to get every single hat (but don't quote me!).
You would have to go through the up-most path twice, going through levels 3, 4, 8, 9, 16, 17, 24, and 25. Then the next path closest twice...