結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
54,920 KB
testcase_01 AC 42 ms
55,604 KB
testcase_02 AC 42 ms
54,812 KB
testcase_03 AC 43 ms
54,520 KB
testcase_04 AC 42 ms
53,944 KB
testcase_05 AC 43 ms
55,260 KB
testcase_06 AC 42 ms
54,852 KB
testcase_07 AC 42 ms
55,164 KB
testcase_08 WA -
testcase_09 AC 278 ms
88,960 KB
testcase_10 AC 290 ms
89,220 KB
testcase_11 AC 220 ms
85,092 KB
testcase_12 AC 262 ms
88,516 KB
testcase_13 AC 135 ms
79,928 KB
testcase_14 AC 230 ms
85,972 KB
testcase_15 AC 45 ms
55,356 KB
testcase_16 AC 204 ms
84,092 KB
testcase_17 AC 236 ms
85,204 KB
testcase_18 AC 179 ms
82,156 KB
testcase_19 AC 228 ms
84,988 KB
testcase_20 AC 121 ms
77,904 KB
testcase_21 AC 191 ms
83,000 KB
testcase_22 AC 159 ms
81,144 KB
testcase_23 AC 98 ms
77,900 KB
testcase_24 AC 111 ms
77,740 KB
testcase_25 AC 113 ms
77,960 KB
testcase_26 AC 246 ms
85,960 KB
testcase_27 WA -
testcase_28 AC 167 ms
89,236 KB
testcase_29 AC 166 ms
89,496 KB
testcase_30 AC 187 ms
97,460 KB
testcase_31 AC 200 ms
101,520 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]]) 

same = 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