cities, edges: (1,2), (1,3), (4,5). c_lib = 3, c_road = 2.
Connected components: {1,2,3} (size ) and {4,5} (size ).
Component {1,2,3}: option A = . Option B = . Pick A: .
Component {4,5}: option A = . Option B = . Pick A: .
Total: .
Finding components with DFS visits each node and edge once: time. The adjacency list and visited array take space.