Shiva Arranging Gears

1

1 votes
Easy-Medium, Easy-Medium
Problem

There are N gears arranged in some manner such that some of the gears are touching other gears(teeth/cogs mesh with toothed part of another gear).

One can easily see that if one of the gear is moving in clockwise direction, then the gears that are touching to that gear should move in anti-clockwise direction. But sometimes, due to the arrangement of the gears, it is impossible to have such a movement of gears. Lets call this situation a lockdown situation.

Given a situation of gears, if it is a lockdown free situation print "YES" else print "NO". (without quotes)

INPUT:

First line will contain an integer T denoting the number of test cases. Each test case will begin with 2 integers, N and M, denoting the number of gears and number of contacts between the gears. Following M lines will have 2 integers A and B, denoting that the gears A and B are touching each other.

OUTPUT:

For each testcase, in a new line, you need to print "YES" if its a lockdown free situation or "NO" otherwise, without quotes.

CONSTRAINTS:

1<=T<=10

1<=N<=10^5

1<=M<=10^5

1<=A,B<=N (A!=B)

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?