No.2664 Prime Sum
Problem Statement
You are given a positive integer $n$ and $m$ integer pairs $(a _ i, b _ i)\ (i = 1, 2, \ldots, m)$.
Here, $a _ i,b _ i$ are integers between $1$ and $n$, inclusive, and it is guaranteed that $a _ i \neq b _ i$.
Determine whether there exists a sequence $X = (X _ 1, X _ 2, \ldots, X _ n)$ of length $n$ that satisfies all of the following conditions.
- For all $i = 1, 2, \ldots, n$, $X _ i$ is an integer greater than or equal to $2$
- For all $i = 1, 2, \ldots, m$, $X _ {a _ i} + X _ {b _ i}$ is a prime number
Input
The input is given from Standard Input in the following format.
$n\ m$ $a _ 1\ b _ 1$ $a _ 2\ b _ 2$ $\vdots$ $a _ m\ b _ m$
- All input values are integers
- $2\leq n\leq 100$
- $1\leq m\leq \dfrac{n(n-1)}{2}$
- $1\leq a _ i, b _ i\leq n$
- $a_i\neq b_i$ for all integers $i$ such that $1\leq i\leq m$
- $(a_i,b_i)\neq (a_j,b_j)$ and $(a_i,b_i)\neq (b_j,a_j)$ for all integers $i,j$ such that $1\leq i\lt j\leq m$
Output
If $X$ satisfying the conditions exists, print Yes; otherwise, print No. Print the answer on $1$ line, followed by a newline.
Sample
Sample 1
Input
4 4 1 2 2 3 3 4 4 1
Output
Yes
The input represents $n = 4,\ m = 4, (a _ 1, b _ 1) = (1, 2),\ (a _ 2, b _ 2) = (2, 3),\ (a _ 3, b _ 3) = (3, 4),\ (a _ 4, b _ 4) = (4, 1)$.
For example, taking $X = (2,3,8,5)$ does satisfy the conditions, so print Yes as the answer.
Sample 2
Input
5 10 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5
Output
No
It can be proved that no $X$ satisfying the conditions exists.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
cureskol