Project Euler 186 - Connectedness of a Network

Official link: https://projecteuler.net/problem=186