Neighbors

AtCoder
IDabc231_d
Time2000ms
Memory256MB
Difficulty
Determine whether there is a way to line up $N$ people, numbered $1$ to $N$, in a row side by side to satisfy all of the $M$ conditions in the following format. * Condition: Person $A_i$ and Person $B_i$ are adjacent. ## Constraints * $2 \leq N \leq 10^5$ * $0 \leq M \leq 10^5$ * $1\leq A_i < B_i \leq N$ * All pairs $(A_i,B_i)$ are distinct. ## Input Input is given from Standard Input in the following format: $N$ $M$ $A_1$ $B_1$ $\vdots$ $A_M$ $B_M$ [samples]
Samples
Input #1
4 2
1 3
2 3
Output #1
Yes

One way to satisfy all the conditions is to line them up in the order $4,1,3,2$.
Input #2
4 3
1 4
2 4
3 4
Output #2
No

There is no way to line them up to satisfy all the conditions.
API Response (JSON)
{
  "problem": {
    "name": "Neighbors",
    "description": {
      "content": "Determine whether there is a way to line up $N$ people, numbered $1$ to $N$, in a row side by side to satisfy all of the $M$ conditions in the following format. *   Condition: Person $A_i$ and Person",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc231_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Determine whether there is a way to line up $N$ people, numbered $1$ to $N$, in a row side by side to satisfy all of the $M$ conditions in the following format.\n\n*   Condition: Person $A_i$ and Person...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments