結果
| 問題 | No.1424 Ultrapalindrome |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-30 15:19:29 |
| 言語 | Python3 (3.14.2 + numpy 2.4.0 + scipy 1.16.3) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 724 bytes |
| 記録 | |
| コンパイル時間 | 77 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 480,640 KB |
| 最終ジャッジ日時 | 2024-06-11 08:17:49 |
| 合計ジャッジ時間 | 6,304 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 TLE * 1 -- * 13 |
ソースコード
from collections import deque
n=int(input())
g=[[] for _ in range(n)]
in_num=[0]*n
for _ in range(n-1):
a,b=map(int,input().split())
g[a-1].append(b-1)
g[b-1].append(a-1)
cnt_3=0
for i in range(n):
if len(g[i])>=3:
cnt_3+=1
if cnt_3>=2:
print('No')
elif cnt_3==0:
print('Yes')
else:
q=deque()
for i in range(n):
if len(g[i])==1:
q.append((i,-1,0))
D=set()
while q:
now,pre,d=q.popleft()
for to in g[now]:
if to==pre:
continue
if len(g[to])==1:
D.add(d+1)
continue
q.append((to,now,d+1))
if len(D)==1:
print('Yes')
else:
print('No')