Part 2 could be done using the same code as part 1 with a few modifications:
- Use both start and end node as parameters.
- Add memoization
Then the call would be something like:
dfs("svr", "fft", memo_structure);
dfs("fft", "dac", memo_structure);
dfs("dac", "out", memo_structure);
Source:
https://www.reddit.com/r/adventofcode/comments/1pjrojm/comment/ntfo2vm/?share_id=82ZprKj1OEnobohhcZsIC&utm_content=2&utm_medium=android_app&utm_name=androidcss&utm_source=share&utm_term=14