結果
問題 |
No.1424 Ultrapalindrome
|
ユーザー |
![]() |
提出日時 | 2025-02-28 21:52:43 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,176 bytes |
コンパイル時間 | 206 ms |
コンパイル使用メモリ | 82,712 KB |
実行使用メモリ | 101,852 KB |
最終ジャッジ日時 | 2025-02-28 21:52:50 |
合計ジャッジ時間 | 6,067 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 WA * 2 |
ソースコード
from collections import Counter N = int(input()) AB = [list(map(int,input().split())) for _ in range(N-1)] D = [0] * N E = [[] for _ in range(N)] for a, b in AB: a -= 1 b -= 1 E[a].append(b) E[b].append(a) D[a] += 1 D[b] += 1 C = Counter(D) ''' 次以外の時はNO 次数1の数2で残り全部2の時 次数2の数が次数1の数の定数倍で次数が次数1の数である頂点がある ''' def check(x,x1): nv = [1] * N nv[x] = 0 Q = [x] Q2 = [] while Q: while Q: x = Q.pop() for y in E[x]: if nv[y]: nv[y] = 0 Q2.append(y) if not(len(Q2) != x1 or len(Q2) != 0): return False Q,Q2 = Q2,Q return True x1 = C[1] x2 = C[2] NC = len(C) f = False if x1 == 2: if x2 == 0: if NC == 1: f = True else: if NC == 2: f = True else: if x2 == 0: if D[x1] == 1 and NC == 2: f = True elif x2 % x1 == 0: if C[x1] == 1 and NC == 3: st = D.index(x1) f = check(st,x1) if f: print("Yes") else: print("No")