Codeforces Rd #368 (Div. 2) Problem B

In this problem, one of the task is to identify whether the city has a storage.

for city in cities:
	if city in has_storage:
		# Do Something

One important thing to get rid of time exceed error is to use set, instead of list, for has_storage.

According to Python Wiki, the average case for

x in list

is O(n),

x in set

is O(1).

This stackoverflow thread also illustrated the time difference.