結果

問題 No.1424 Ultrapalindrome
ユーザー hir355hir355
提出日時 2021-03-12 21:44:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 855 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 82,464 KB
実行使用メモリ 105,872 KB
最終ジャッジ日時 2024-04-22 12:35:01
合計ジャッジ時間 5,701 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,508 KB
testcase_01 AC 38 ms
53,392 KB
testcase_02 AC 38 ms
52,796 KB
testcase_03 AC 36 ms
52,752 KB
testcase_04 AC 38 ms
52,500 KB
testcase_05 AC 38 ms
51,944 KB
testcase_06 AC 37 ms
53,376 KB
testcase_07 WA -
testcase_08 AC 38 ms
52,984 KB
testcase_09 AC 238 ms
86,868 KB
testcase_10 AC 243 ms
86,872 KB
testcase_11 AC 180 ms
83,456 KB
testcase_12 AC 226 ms
86,212 KB
testcase_13 AC 118 ms
78,576 KB
testcase_14 AC 196 ms
84,692 KB
testcase_15 AC 42 ms
53,920 KB
testcase_16 AC 171 ms
82,780 KB
testcase_17 AC 186 ms
83,084 KB
testcase_18 AC 149 ms
81,744 KB
testcase_19 AC 189 ms
84,660 KB
testcase_20 AC 105 ms
77,808 KB
testcase_21 AC 166 ms
82,536 KB
testcase_22 AC 139 ms
80,908 KB
testcase_23 AC 87 ms
77,404 KB
testcase_24 AC 102 ms
77,872 KB
testcase_25 AC 103 ms
77,928 KB
testcase_26 AC 224 ms
86,144 KB
testcase_27 AC 296 ms
96,556 KB
testcase_28 AC 158 ms
89,644 KB
testcase_29 AC 157 ms
89,968 KB
testcase_30 AC 173 ms
98,844 KB
testcase_31 AC 180 ms
105,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
g = [[] for _ in range(n)]
vi = [0] * n
for _ in range(n - 1):
    a, b = map(int, input().split())
    vi[a - 1] += 1
    vi[b - 1] += 1
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)
s = [0]
d = [-1] * n
d[0] = 0
while s:
    p = s.pop()
    for node in g[p]:
        if d[node] == -1:
            d[node] = d[p] + 1
            s.append(node)
k = d.index(max(d))
s = [k]
d = [-1] * n
d[k] = 0
while s:
    p = s.pop()
    for node in g[p]:
        if d[node] == -1:
            d[node] = d[p] + 1
            s.append(node)
r = max(d)
if r % 2 == 1:
    for i in range(n):
        if vi[i] >= 3:
            print('No')
            break
    else:
        print('Yes')
else:
    c = d.index(r // 2)
    for i in range(n):
        if i != c and vi[i] >= 3:
            print('No')
            break
    else:
        print('Yes')
0