結果

問題 No.1424 Ultrapalindrome
ユーザー 👑 H20H20
提出日時 2021-03-12 23:37:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 1,253 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 82,036 KB
実行使用メモリ 101,440 KB
最終ジャッジ日時 2024-04-22 17:16:36
合計ジャッジ時間 5,714 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
54,144 KB
testcase_01 AC 46 ms
53,632 KB
testcase_02 AC 44 ms
53,760 KB
testcase_03 AC 45 ms
53,504 KB
testcase_04 AC 43 ms
53,888 KB
testcase_05 AC 44 ms
53,760 KB
testcase_06 AC 44 ms
54,016 KB
testcase_07 AC 43 ms
54,016 KB
testcase_08 AC 44 ms
54,016 KB
testcase_09 AC 167 ms
84,912 KB
testcase_10 AC 151 ms
84,612 KB
testcase_11 AC 137 ms
82,048 KB
testcase_12 AC 151 ms
84,444 KB
testcase_13 AC 103 ms
78,336 KB
testcase_14 AC 129 ms
82,076 KB
testcase_15 AC 47 ms
54,528 KB
testcase_16 AC 131 ms
81,792 KB
testcase_17 AC 125 ms
81,920 KB
testcase_18 AC 173 ms
82,944 KB
testcase_19 AC 198 ms
84,800 KB
testcase_20 AC 124 ms
78,080 KB
testcase_21 AC 166 ms
83,072 KB
testcase_22 AC 153 ms
80,896 KB
testcase_23 AC 95 ms
77,848 KB
testcase_24 AC 120 ms
77,952 KB
testcase_25 AC 113 ms
78,720 KB
testcase_26 AC 229 ms
86,408 KB
testcase_27 AC 194 ms
89,292 KB
testcase_28 AC 175 ms
89,396 KB
testcase_29 AC 162 ms
89,400 KB
testcase_30 AC 195 ms
98,116 KB
testcase_31 AC 191 ms
101,440 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 = []
overT = False
for i in range(N):
    if len(L[i])==1:
        CHECK.append(i)
    if overT and len(L[i])>=3:
        print('No')
        exit()
    if len(L[i])>=3:
        overT = True


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

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