結果
| 問題 |
No.1424 Ultrapalindrome
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-12 21:54:19 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 739 bytes |
| コンパイル時間 | 177 ms |
| コンパイル使用メモリ | 82,248 KB |
| 実行使用メモリ | 98,220 KB |
| 最終ジャッジ日時 | 2024-10-14 16:14:09 |
| 合計ジャッジ時間 | 5,388 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 WA * 1 |
ソースコード
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)
if len(cand) > 2:
search(2)
print("Yes")