Scan for any stations that only have 1 train trip. These represent the end of a branching subway line. Look at its neighbors until you reach a neighbor that has >2 train trips. Reduce all the branching stations into a single station representing that branch.
Scan for any stations that only have 1 train trip. These represent the end of a branching subway line. Look at its neighbors until you reach a neighbor that has >2 train trips. Reduce all the branching stations into a single station representing that branch.