Can you please help me solve this?

The root port cost is the same from the root bridge to SW1 over interfaces Gi0/1-2 on SW2. Root would advertise a root port cost of 0 and SW1 would add it's local root port cost on the interfaces to 0 (Both being 4 in this case, root port cost of 4 to reach root SW2). So the root port selection with default root port costs, should select Gi0/1 as the root port because it should have the lowest interface number. If however, the configuration changed the spanning-tree port cost of Gi0/2 on SW1 to be lower than 4 (default cost for Gig interfaces), Gi0/2 would be elected root port

You'll need to look carefully at the interface types. Notably, the links from SW5 to SW4, SW5 to SW3, SW3 to SW4, and SW3 to SW1. Because they are FastEthernet interfaces, the default port cost is 19. Even though Gi0/2 on SW3 is Gig, it will be set the interface to 100 because that's the highest speed Fa0/1 on SW5 supports. Spanning-Tree selects speeds and costs on the running speed, not what the hardware supports. From there, just imagine nothing is blocked or designated, and do the math for all the paths to reach SW5 using the default port costs.

I.G. - Root Switch (0) to Gi0/4 on SW4 (4) to Gi0/3 on SW6 (4) to Gi0/1 or GI0/2 (4) = Root Port Cost of 12. If SW5 went out Fa0/1-2 the port cost would be 19. Since this is higher than 12 and I haven't considered other port costs yet, it makes sense these won't become the root port because I still have a couple of paths with Gig interfaces I could add. SW5, in this instance, could only choose port Gi0/2 as the root port if the configuration was changed to modify the root port cost to be lower than 4 as previously explained above.

/r/ccna Thread