結果

問題 No.1424 Ultrapalindrome
ユーザー hir355hir355
提出日時 2021-03-12 21:49:49
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 969 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 105,624 KB
最終ジャッジ日時 2024-04-22 12:43:07
合計ジャッジ時間 6,710 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 38 ms
51,840 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 37 ms
52,224 KB
testcase_05 AC 36 ms
52,224 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 37 ms
51,968 KB
testcase_09 AC 189 ms
86,912 KB
testcase_10 AC 188 ms
87,168 KB
testcase_11 AC 150 ms
82,944 KB
testcase_12 AC 188 ms
86,144 KB
testcase_13 AC 112 ms
78,720 KB
testcase_14 AC 168 ms
84,992 KB
testcase_15 AC 44 ms
53,376 KB
testcase_16 AC 144 ms
82,560 KB
testcase_17 AC 159 ms
83,328 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 393 ms
96,640 KB
testcase_28 RE -
testcase_29 AC 203 ms
89,856 KB
testcase_30 RE -
testcase_31 AC 231 ms
105,624 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')
        exit(1)
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')
            exit(1)
0