結果
| 問題 | No.1424 Ultrapalindrome |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-12 21:52:24 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 707 bytes |
| 記録 | |
| コンパイル時間 | 165 ms |
| コンパイル使用メモリ | 82,096 KB |
| 実行使用メモリ | 97,344 KB |
| 最終ジャッジ日時 | 2024-10-14 12:14:21 |
| 合計ジャッジ時間 | 5,309 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 WA * 2 |
ソースコード
from collections import deque
n = int(input())
e = [[] for i in range(n)]
for i in range(n-1):
a,b = map(int,input().split())
a -= 1
b -= 1
e[a].append(b)
e[b].append(a)
cand = []
for i in range(n):
if len(e[i]) == 1:
cand.append(i)
def search(ind):
dis = [10**10]*n
dis[cand[ind]] = 0
q = deque([cand[ind]])
while q:
now = q.popleft()
for nex in e[now]:
if dis[nex] > dis[now]+1:
dis[nex] = dis[now]+1
q.append(nex)
num = dis[cand[(ind+1)%len(cand)]]
for i in cand:
if i != cand[ind] and num != dis[i]:
print("No")
exit()
search(0)
search(1)
print("Yes")