QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#14552. Connection Game

Statistics

There are $n$ points distributed equally along a unit circle in counter-clockwise order, labeled $0, 1, 2, \dots, n-1$.

Initially, there are $m$ line segments. The $i$-th line segment connects points $x_i$ and $y_i$ ($x_i, y_i$). It is guaranteed that the $m$ initial line segments do not intersect at their endpoints, i.e., for all $1 \le i < j \le m$, the sets $\{x_i, y_i\}$ and $\{x_j, y_j\}$ are disjoint.

Alice and Bob play a game on these points and line segments with the following rules:

  • The players take turns, with Alice going first.
  • In each turn, a player must choose two points that are not yet occupied by any line segment and draw a line segment between them. The new line segment must not intersect any existing line segments (including the initial ones and those added in previous turns) inside the circle.
  • A player who cannot make a move according to the above rules loses the game.

Given $n, m$ and the $m$ initial line segments, determine whether the first player, Alice, has a winning strategy, assuming both players play optimally. If Alice has a winning strategy, output YES; otherwise, output NO.

Input

The input contains multiple test cases. The first line contains a single positive integer $T$ ($1 \le T \le 10^5$) representing the number of test cases.

For each test case:

  • The first line contains two integers $n$ ($2 \le n \le 10^9$) and $m$ ($0 \le m \le 10^5$), representing the total number of points and the number of initial line segments, respectively.
  • The next $m$ lines each contain two integers $x_i, y_i$, describing an initial line segment, where $0 \le x_i, y_i < n$ and $x_i \neq y_i$. It is guaranteed that for all $1 \le i < j \le m$, the sets $\{x_i, y_i\}$ and $\{x_j, y_j\}$ are disjoint.

The data guarantees that the sum of $m$ over all test cases does not exceed $10^5$, i.e., $\sum m \le 10^5$.

Output

Output $T$ lines, representing the answers for the $T$ test cases. For each test case, if Alice has a winning strategy, output YES; otherwise, output NO.

Examples

Input 1

2
2 0
5 0

Output 1

YES
NO

Input 2

2
8 1
0 4
11 2
0 6
8 3

Output 2

NO
YES

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.