結果

問題 No.3220 Forest Creation
ユーザー Nauclhlt🪷
提出日時 2025-06-29 16:29:29
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 913 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 12,288 KB
実行使用メモリ 21,100 KB
最終ジャッジ日時 2025-07-04 20:47:54
合計ジャッジ時間 3,669 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    try:
        N = int(input().strip())
    except:
        print("No")
        return
    A = list(map(int, input().split()))
    if len(A) != N + 1:
        print("No")
        return

    # Total number of vertices
    n = sum(A)
    # Total degree sum
    S = sum(i * A[i] for i in range(N + 1))

    # Empty forest is allowed
    if n == 0:
        print("Yes")
        return
    # Condition 1: S is even
    if S % 2 != 0:
        print("No")
        return
    # Number of edges
    E = S // 2
    # Condition 2: edges <= vertices - 1 (only if n >= 1)
    if n >= 1 and E > n - 1:
        print("No")
        return
    # Condition 3: max degree <= n - 1 (only if n >= 1)
    if n >= 1:
        max_deg = max((i for i, cnt in enumerate(A) if cnt > 0), default=0)
        if max_deg > n - 1:
            print("No")
            return

    print("Yes")

if __name__ == '__main__':
    main()
0