結果

問題 No.1424 Ultrapalindrome
ユーザー 👑 H20H20
提出日時 2021-03-12 22:22:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,062 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 101,576 KB
最終ジャッジ日時 2024-04-22 13:24:26
合計ジャッジ時間 6,398 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,888 KB
testcase_01 AC 42 ms
53,760 KB
testcase_02 AC 42 ms
53,632 KB
testcase_03 AC 42 ms
53,632 KB
testcase_04 AC 42 ms
54,016 KB
testcase_05 AC 42 ms
53,248 KB
testcase_06 AC 42 ms
53,632 KB
testcase_07 AC 42 ms
54,016 KB
testcase_08 WA -
testcase_09 AC 224 ms
88,832 KB
testcase_10 AC 235 ms
88,900 KB
testcase_11 AC 188 ms
84,864 KB
testcase_12 AC 214 ms
88,800 KB
testcase_13 AC 134 ms
80,168 KB
testcase_14 AC 199 ms
85,656 KB
testcase_15 AC 46 ms
54,656 KB
testcase_16 AC 178 ms
84,096 KB
testcase_17 AC 201 ms
85,376 KB
testcase_18 AC 157 ms
82,304 KB
testcase_19 AC 190 ms
84,924 KB
testcase_20 AC 115 ms
77,952 KB
testcase_21 AC 165 ms
82,944 KB
testcase_22 AC 151 ms
81,280 KB
testcase_23 AC 98 ms
77,696 KB
testcase_24 AC 109 ms
77,896 KB
testcase_25 AC 112 ms
77,788 KB
testcase_26 AC 211 ms
85,648 KB
testcase_27 WA -
testcase_28 AC 161 ms
89,152 KB
testcase_29 AC 167 ms
89,280 KB
testcase_30 AC 184 ms
98,108 KB
testcase_31 AC 194 ms
101,576 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