Write a program to detect cycles in a directed graph, representing dependencies in a vehicle state machine.
Implement has_cycle(graph), where graph is a dictionary mapping each state to a list of states it can transition to. Return True if any directed cycle exists, otherwise return False. The graph may contain disconnected components, and every referenced state is present as a key.
def has_cycle(graph):