Solve UVa 315 - Network.