#ARC161F. [ARC161F] Everywhere is Sparser than Whole (Judge)

[ARC161F] Everywhere is Sparser than Whole (Judge)

Score : 900900 points

Problem Statement

We define the density of a non-empty simple undirected graph as $\displaystyle\frac{(\text{number\ of\ edges})}{(\text{number\ of\ vertices})}$.

You are given positive integers NN, DD, and a simple undirected graph GG with NN vertices and DNDN edges. The vertices of GG are numbered from 11 to NN, and the ii-th edge connects vertex AiA_i and vertex BiB_i. Determine whether GG satisfies the following condition.

Condition: Let VV be the vertex set of GG. For any non-empty proper subset XX of VV, the density of the induced subgraph of GG by XX is strictly less than DD.

There are TT test cases to solve.

What is an induced subgraph?

For a vertex subset XX of graph GG, the induced subgraph of GG by XX is the graph with vertex set XX and edge set containing all edges of GG that connect two vertices in XX. In the above condition, note that we only consider vertex subsets that are neither empty nor the entire set.

Constraints

  • T1T \geq 1
  • N1N \geq 1
  • D1D \geq 1
  • The sum of DNDN over the test cases in each input file is at most 5×1045 \times 10^4.
  • 1Ai<BiN  (1iDN)1 \leq A_i < B_i \leq N \ \ (1 \leq i \leq DN)
  • $(A_i, B_i) \neq (A_j, B_j) \ \ (1 \leq i < j \leq DN)$

Input

The input is given from Standard Input in the following format:

TT

case1\mathrm{case}_1

case2\mathrm{case}_2

\vdots

caseT\mathrm{case}_T

Each test case casei (1iT)\mathrm{case}_i \ (1 \leq i \leq T) is in the following format:

NN DD

A1A_1 B1B_1

A2A_2 B2B_2

\vdots

ADNA_{DN} BDNB_{DN}

Output

Print TT lines. The ii-th line should contain Yes if the given graph GG for the ii-th test case satisfies the condition, and No otherwise.

2
3 1
1 2
1 3
2 3
4 1
1 2
1 3
2 3
3 4
Yes
No
  • The first test case is the same as Sample Input 1 in Problem D

    , and it satisfies the condition.

  • For the second test case, the edge set of the induced subgraph by the non-empty proper subset {1,2,3}\{1, 2, 3\} of the vertex set {1,2,3,4}\{1, 2, 3, 4\} is {(1,2),(1,3),(2,3)}\{(1, 2), (1, 3), (2, 3)\}, and its density is 33=1=D\displaystyle\frac{3}{3} = 1 = D. Therefore, this graph does not satisfy the condition.