結果
| 問題 | No.1424 Ultrapalindrome |
| コンテスト | |
| ユーザー |
rodea
|
| 提出日時 | 2021-03-18 15:43:33 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
AC
|
| 実行時間 | 531 ms / 2,000 ms |
| コード長 | 747 bytes |
| 記録 | |
| コンパイル時間 | 420 ms |
| コンパイル使用メモリ | 20,824 KB |
| 実行使用メモリ | 40,412 KB |
| 最終ジャッジ日時 | 2026-05-12 00:14:59 |
| 合計ジャッジ時間 | 9,881 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
import queue
n = int(input())
G = [[] for i in range(n)]
for i in range(n - 1):
a, b = map(int, input().split())
a -= 1
b -= 1
G[a].append(b)
G[b].append(a)
deg3 = 0
cv = -1
for i in range(n):
if 3 <= len(G[i]):
deg3 += 1
cv = i
if deg3 >= 2:
print("No")
exit()
if deg3 == 0:
print("Yes")
exit()
que = queue.Queue()
que.put([cv, 0])
visited = [False for i in range(n)]
visited[cv] = True
leaf = set()
while not que.empty():
cv, d = que.get()
is_leaf = True
for nv in G[cv]:
if visited[nv]: continue
visited[nv] = True
is_leaf = False
que.put([nv, d + 1])
if is_leaf: leaf.add(d)
if len(leaf) == 1:
print("Yes")
else:
print("No")
rodea