結果

問題 No.1424 Ultrapalindrome
ユーザー kohei2019kohei2019
提出日時 2022-05-19 01:17:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,063 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 81,456 KB
実行使用メモリ 99,956 KB
最終ジャッジ日時 2023-10-17 07:03:07
合計ジャッジ時間 7,987 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,312 KB
testcase_01 AC 44 ms
55,312 KB
testcase_02 AC 43 ms
55,312 KB
testcase_03 AC 43 ms
55,312 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 43 ms
55,312 KB
testcase_07 AC 43 ms
55,312 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 164 ms
82,448 KB
testcase_19 AC 199 ms
84,780 KB
testcase_20 AC 114 ms
77,616 KB
testcase_21 AC 165 ms
82,748 KB
testcase_22 AC 141 ms
80,640 KB
testcase_23 AC 92 ms
77,348 KB
testcase_24 AC 109 ms
77,496 KB
testcase_25 AC 110 ms
77,420 KB
testcase_26 AC 219 ms
87,544 KB
testcase_27 WA -
testcase_28 AC 146 ms
87,880 KB
testcase_29 AC 162 ms
90,432 KB
testcase_30 AC 178 ms
97,912 KB
testcase_31 AC 179 ms
99,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
N = int(input())
lsg = [[] for i in range(N)]
lsj = [0]*(N)
for i in range(N-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    lsg[a].append(b)
    lsg[b].append(a)
    lsj[a] += 1
    lsj[b] += 1

n1 = 0
n2 = 0
n3 = 0
for i in range(N):
    if lsj[i] == 1:
        n1 += 1
    elif lsj[i] == 2:
        n2 += 1
    else:
        n3 += 1

if n1 == 2 and n2 == N-2: #直線
    print('Yes')
    exit()

if n3 >= 2: #分岐が複数×
    print('NO')
    exit()

root = 0
for i in range(N):
    if lsj[i] >= 3:
        root = i
        break

d = collections.deque([root])
used = [False]*(N)
lsc = [float('INF')]*(N)
lsc[root] = 0
while d:
    n = d.popleft()
    if used[n]:
        continue
    used[n] = True
    for j in lsg[n]:
        if used[j]:
            continue
        if lsc[j] > lsc[n] + 1:
            lsc[j] = lsc[n] + 1
            d.append(j)

ll = []
for i in range(N):
    if lsj[i] == 1:
        ll.append(lsc[i])

cnt = len(collections.Counter(ll).keys())
if cnt == 1:
    print('Yes')
else:
    print('No')
0