IMC Trading Interview Question

use dfs to traverse the graph