Switch port information is as follows:

The graph is: the relationship between switches and server

Switch the port connection object:
Switch 1
Port 1: switch 2; Switch 3 port 2:
Switch 2
Port 1: server 1; Port 2: the server 2; Port 3: switch 1
Switch 3
Port 1: the server 3; Port 2: switch 1
You think what kind of algorithm is better, if you can post implementation code to discuss with us