結果
| 問題 |
No.1424 Ultrapalindrome
|
| コンテスト | |
| ユーザー |
ntuda
|
| 提出日時 | 2025-02-28 22:00:18 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 197 ms / 2,000 ms |
| コード長 | 1,176 bytes |
| コンパイル時間 | 530 ms |
| コンパイル使用メモリ | 82,772 KB |
| 実行使用メモリ | 101,920 KB |
| 最終ジャッジ日時 | 2025-02-28 22:00:26 |
| 合計ジャッジ時間 | 5,175 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
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 C[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")
ntuda