結果

問題 No.1424 Ultrapalindrome
ユーザー hir355hir355
提出日時 2021-03-12 21:47:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 933 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 105,748 KB
最終ジャッジ日時 2024-04-22 12:38:18
合計ジャッジ時間 5,595 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,052 KB
testcase_01 AC 39 ms
52,444 KB
testcase_02 AC 39 ms
52,924 KB
testcase_03 AC 38 ms
52,484 KB
testcase_04 AC 39 ms
52,600 KB
testcase_05 AC 38 ms
53,152 KB
testcase_06 AC 39 ms
53,548 KB
testcase_07 WA -
testcase_08 AC 39 ms
53,256 KB
testcase_09 AC 239 ms
87,080 KB
testcase_10 AC 243 ms
86,860 KB
testcase_11 AC 182 ms
83,596 KB
testcase_12 AC 229 ms
86,712 KB
testcase_13 AC 116 ms
78,900 KB
testcase_14 AC 196 ms
85,320 KB
testcase_15 AC 41 ms
54,140 KB
testcase_16 AC 166 ms
82,592 KB
testcase_17 AC 183 ms
83,392 KB
testcase_18 AC 150 ms
82,264 KB
testcase_19 AC 198 ms
84,296 KB
testcase_20 AC 106 ms
77,948 KB
testcase_21 AC 171 ms
82,944 KB
testcase_22 AC 142 ms
80,664 KB
testcase_23 AC 88 ms
77,336 KB
testcase_24 AC 104 ms
78,180 KB
testcase_25 AC 104 ms
78,052 KB
testcase_26 AC 230 ms
85,776 KB
testcase_27 AC 305 ms
96,576 KB
testcase_28 AC 158 ms
89,808 KB
testcase_29 AC 159 ms
89,764 KB
testcase_30 AC 169 ms
98,844 KB
testcase_31 AC 181 ms
105,748 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)
    if d.count(c) >= 2:
        print('No')
    else:
        for i in range(n):
            if i != c and vi[i] >= 3:
                print('No')
                break
        else:
            print('Yes')
0