結果
問題 |
No.3220 Forest Creation
|
ユーザー |
![]() |
提出日時 | 2025-06-29 16:28:27 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 836 bytes |
コンパイル時間 | 526 ms |
コンパイル使用メモリ | 12,160 KB |
実行使用メモリ | 20,836 KB |
最終ジャッジ日時 | 2025-07-04 20:47:50 |
合計ジャッジ時間 | 4,315 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 42 WA * 3 |
ソースコード
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 if E > n - 1: print("No") return # Condition 3: max degree <= 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()