#K94637. Taco Tour

    ID: 38686 Type: Default 1000ms 256MiB

Taco Tour

Taco Tour

You are given a set of flights between cities, each flight represented as a directed edge from one city to another. Your task is to determine whether it is possible to start from some city, travel along each flight exactly once, and return to the starting city.

This problem is equivalent to determining if there exists an Eulerian circuit in the directed graph constructed from the flights. Recall that for an Eulerian circuit to exist in a directed graph, the following conditions must be satisfied:

  • Every city (vertex) that appears in the flight list must have equal in-degree and out-degree.
  • All cities with nonzero degree must be reachable from any starting city (i.e. the graph must be connected in the sense of being able to traverse the directed edges where possible).

If these conditions are met, output YES; otherwise, output NO.

inputFormat

The first line of input contains an integer n representing the number of flights.

The following n lines each contain two space-separated strings that represent the source and destination cities of a flight.

outputFormat

Output a single line containing either YES if a tour satisfying the conditions exists, or NO otherwise.

## sample
4
A B
C D
B C
D A
YES