結果

問題 No.1424 Ultrapalindrome
ユーザー 👑 H20H20
提出日時 2021-03-12 22:32:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,063 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 82,184 KB
実行使用メモリ 101,700 KB
最終ジャッジ日時 2024-04-22 13:36:51
合計ジャッジ時間 6,203 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
54,272 KB
testcase_01 AC 48 ms
54,016 KB
testcase_02 AC 42 ms
54,144 KB
testcase_03 AC 43 ms
54,272 KB
testcase_04 AC 43 ms
53,888 KB
testcase_05 AC 44 ms
53,888 KB
testcase_06 AC 43 ms
53,888 KB
testcase_07 AC 44 ms
53,760 KB
testcase_08 WA -
testcase_09 AC 270 ms
89,004 KB
testcase_10 AC 274 ms
89,024 KB
testcase_11 AC 214 ms
84,860 KB
testcase_12 AC 254 ms
89,180 KB
testcase_13 AC 141 ms
79,920 KB
testcase_14 AC 224 ms
85,668 KB
testcase_15 AC 46 ms
55,168 KB
testcase_16 AC 196 ms
84,056 KB
testcase_17 AC 216 ms
85,448 KB
testcase_18 AC 176 ms
82,476 KB
testcase_19 AC 224 ms
85,048 KB
testcase_20 AC 124 ms
78,208 KB
testcase_21 AC 190 ms
83,072 KB
testcase_22 AC 158 ms
80,836 KB
testcase_23 AC 99 ms
77,696 KB
testcase_24 AC 115 ms
78,080 KB
testcase_25 AC 115 ms
77,952 KB
testcase_26 AC 247 ms
86,416 KB
testcase_27 WA -
testcase_28 AC 169 ms
89,332 KB
testcase_29 AC 171 ms
89,528 KB
testcase_30 AC 190 ms
97,688 KB
testcase_31 AC 199 ms
101,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())
L = []
for i in range(N):
    L.append([])
for i in range(N-1):
    a,b = map(int, input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)
CHECK = []
for i in range(N):
    if len(L[i])==1:
        CHECK.append(i)
root = CHECK[0]

q = deque()
c = deque()

STEP = [-1]*N
STEP[root]=0
q.append(root)
c.append(0)

while len(q) !=0:
    i = q.popleft()
    cnt = c.popleft()
    for l in L[i]:
        if STEP[l]==-1:
            STEP[l]=cnt+1
            q.append(l)
            c.append(cnt+1)

ans = True
for i in range(len(CHECK)):
    ans = ans and (STEP[CHECK[i]]==0 or STEP[CHECK[i]]==STEP[CHECK[1]]) 

root = CHECK[-1]
STEP = [-1]*N
STEP[root]=0
q.append(root)
c.append(0)

while len(q) !=0:
    i = q.popleft()
    cnt = c.popleft()
    for l in L[i]:
        if STEP[l]==-1:
            STEP[l]=cnt+1
            q.append(l)
            c.append(cnt+1)

for i in range(len(CHECK)):
    ans = ans and (STEP[CHECK[i]]==0 or STEP[CHECK[i]]==STEP[CHECK[0]]) 

if ans:
    print('Yes')
else:
    print('No')
0