Good galaxy

All submissions for this problem are available.

A galaxy is a set of planets with some connections between pairs of planets. Connections between planets are mutual and no planet can be connected with itself. The distance between a pair of planets is the least number of connections that you have to pass through while travelling from the first planet to the second.

Now let's consider how good galaxies are formed.

Initially there is a galaxy that consists of exactly one planet. At any moment, the galaxy grows by first making a copy of itself; then connecting each planet in the first copy to the corresponding planet in the second copy. Thus a galaxy which has P planets and M connections would grow into a new galaxy with 2P planets and 2M+P connections.

This diagram shows how the galaxy grows over the first two iterations. Dark grey shows the copy of the galaxy; light grey shows the additional connections.

However, galaxies do not continue growing forever. Why? The answer is simple: comets. At any point after the galaxy has started growing, a comet may pass through the galaxy. When it does, it changes the connections between planets by the following rule:

Two planets are connected after the comet arrives if and only if the distance between the planets was equal to 2 before the comet arrives.

It can be shown that a comet will split a growing galaxy into two disconnected galaxies with identical structures.

After a comet has arrived, the galaxy stops growing. Researchers have discovered that each of the two identical galaxies formed by the comet are 'good galaxies' - fit for living. In fact, galaxies formed in this way are the only good galaxies that exist.

This diagram shows the result when a comet arrives after each of the first three iterations. In each one the red and blue colours show the two equivalent good galaxies.

Unfortunately, nothing lasts forever. For many reasons, such as a second comet appearing, new planets or connections between them may be created or destroyed, resulting in galaxies with many other structures and causing the galaxy to lose its 'good' status.

You are given a galaxy with N planets and M connections. Your task is to determine whether this galaxy is a good galaxy - ie can be created by a comet passing through a growing galaxy.

Input

The first line of the input contains one integer T denoting the number of test cases.

The first line of each test case contains two integers N and M - the number of planets in the galaxy and the number of connections. All planets are enumerated from 1 to N.

The following M lines each contain a pair of different integers - two planets which are connected in the galaxy. It's guaranteed that there won't be multiple connections between any pair of planets.

Output

For each test case output one word per line: "YES" if the galaxy is a good galaxy, or "NO" if it is not.

Comments

Please login at the top to post a comment.

SUCCESSFUL SUBMISSIONS

Fetching successful submissions

HELP

Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.

Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.

Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.

Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.

Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to INR 20,000 (for Indian Community), $700 (for Global Community) and lots more CodeChef goodies up for grabs.