Orientable as Desired

AtCoder
IDagc071_c
Time2000ms
Memory256MB
Difficulty
There is a simple connected undirected graph $G$ with $N$ vertices and $M$ edges, where the vertices are labeled $1,2,\dots,N$. The $i$\-th edge connects two vertices $u_i$ and $v_i$. Determine whether there exists a length-$N$ sequence of non-negative integers $X=(X_1,X_2,\dots,X_N)$ that satisfies all of the following conditions: * $X_v$ does not exceed the degree of vertex $v$ in $G$ for each $v=1,2,\dots,N$. * There is **no** directed graph obtained by assigning directions to the $M$ edges of $G$ in which, for each $v=1,2,\dots,N$, either the in-degree or the out-degree of $v$ equals $X_v$. You have $T$ test cases; solve each of them. ## Constraints * $1 \leq T \leq 10^5$ * $2 \leq N \leq 2 \times 10^5$ * $N-1 \leq M \leq 2 \times 10^5$ * $1 \leq u_i, v_i \leq N$ * All input values are integers. * The graph $G$ given in the input is a simple connected undirected graph. * The sum of $N$ over all test cases in each input is at most $2 \times 10^5$. * The sum of $M$ over all test cases in each input is at most $2 \times 10^5$. ## Input The input is given from Standard Input in the following format: $T$ $\mathrm{case}_1$ $\vdots$ $\mathrm{case}_T$ Each case is given in the following format: $N$ $M$ $u_1$ $v_1$ $u_2$ $v_2$ $\vdots$ $u_M$ $v_M$ [samples]
Samples
Input #1
3
4 4
1 2
2 3
3 4
4 1
7 6
3 4
3 6
2 5
1 2
1 3
2 7
15 20
11 13
11 7
12 6
5 2
4 1
15 3
9 8
13 5
8 6
7 5
11 8
12 9
14 1
1 11
6 7
1 3
2 3
3 7
5 12
10 6
Output #1
Yes
No
Yes

In the first test case, for example, $X=(2,2,2,1)$ satisfies the conditions.
In the second test case, no sequence $X$ satisfies the conditions.
API Response (JSON)
{
  "problem": {
    "name": "Orientable as Desired",
    "description": {
      "content": "There is a simple connected undirected graph $G$ with $N$ vertices and $M$ edges, where the vertices are labeled $1,2,\\dots,N$. The $i$\\-th edge connects two vertices $u_i$ and $v_i$. Determine whethe",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "agc071_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is a simple connected undirected graph $G$ with $N$ vertices and $M$ edges, where the vertices are labeled $1,2,\\dots,N$. The $i$\\-th edge connects two vertices $u_i$ and $v_i$.\nDetermine whethe...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments