問題一覧 > 通常問題

No.3220 Forest Creation

レベル : / AI推定難易度 : 1500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 35
作問者 : nauclhlt / テスター : 👑 p-adic
お気に入りにしたユーザー ProblemId : 12385 / 自分の提出
問題文最終更新日: 2026-10-22 21:32:17
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 476 (順位表) の他の問題:

Problem Statement

Kero-chan, an indigenous god, can create forests.

Kero-chan is trying to create a forest that satisfies the following conditions.

  • For every $i(0\leq i\leq N)$, there are exactly $A_i$ vertices of degree $i$
  • For $N<i$, the number of vertices of degree $i$ is $0$

Determine whether this is possible. Here, assume that Kero-chan can create any forest.

Note that a graph with no vertices is also considered a forest (when all $A_i$ are $0$, the answer is Yes).

More formal problem statement

Determine whether there exists an undirected graph $G$ that satisfies all of the following conditions.

  • $G$ contains no cycles
  • Letting $D_i$ be the number of vertices in $G$ whose degree is $i$, $A_i=D_i$ for every $i(0\leq i\leq N)$ and $D_i=0$ for $N<i$

About the red text

During the contest, the statement instead contained the sentence "For $N<i$, there is no constraint on the number of vertices of degree $i$." It has been corrected to the content in red.
Since this could be interpreted as changing the problem itself in some cases, we are truly sorry to those who received a wrong verdict because of this.
  • If interpreted as allowing any number of vertices of degree greater than $N$, cases such as $N=1, A=(0, 9)$ would also be Yes, but the intent of the problem when it was written was No
  • Without mention of $N<i$ the statement was somewhat ambiguous, so a sentence was added, but it was worded incorrectly at that time, which led to this situation

Input

$N$
$A_0\ A_1\ A_2\ \cdots\ A_N$
  • $1\leq N\leq 10^5$
  • $0\leq A_i\leq 10^8$
  • All inputs are integers

Output

Print Yes if a forest satisfying the conditions can be created, and No otherwise, on $1$ line.

Print a newline at the end.

Sample

Sample 1
Input
3
0 5 1 1
Output
Yes

For example, you can create the following graph.

   o        o
  /         |
 o - o  o - o - o
Sample 2
Input
2
0 0 3
Output
No

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。