Impromptu Trip (Easy)
InterviewTime limit2sMemory limit1024 MB
Given a directed graph of countries and flights, check whether every country can reach all the others.
Problem
Cheolmin decided to take an impromptu trip across countries to celebrate the end of the semester.
According to Cheolmin's research, there are flights in total among the countries. Each flight has a fixed departure country and arrival country.
Because this is an impromptu trip, Cheolmin will not plan the route in advance. Instead, he made the following plan.
- First, choose a country to start the trip and go there.
- After that, from the current country, take any flight of your choice that departs from it.
- Cheolmin may visit the same country many times, and he may use the same flight many times.
Looking at this plan, you started to worry whether Cheolmin could visit all countries. So you decided to check in advance whether he can visit all countries no matter which starting point he chooses.
Input
The first line contains the number of countries and the number of flights . (, )
From the second line onward, the lines each contain two integers and . This means there is a flight that departs from country and arrives at country . (, )
Output
Print Yes if, for any starting country, there is a route that visits all countries. Otherwise, print No.