結果

問題 No.1424 Ultrapalindrome
ユーザー convexineqconvexineq
提出日時 2021-03-13 02:47:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 631 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 95,428 KB
最終ジャッジ日時 2024-04-22 16:13:36
合計ジャッジ時間 4,426 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,096 KB
testcase_01 WA -
testcase_02 AC 38 ms
51,840 KB
testcase_03 AC 36 ms
51,968 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 39 ms
51,968 KB
testcase_07 WA -
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 113 ms
80,256 KB
testcase_19 AC 131 ms
82,048 KB
testcase_20 AC 91 ms
77,568 KB
testcase_21 AC 118 ms
81,280 KB
testcase_22 AC 100 ms
78,080 KB
testcase_23 AC 73 ms
73,728 KB
testcase_24 AC 87 ms
77,568 KB
testcase_25 AC 95 ms
77,056 KB
testcase_26 AC 147 ms
83,840 KB
testcase_27 WA -
testcase_28 AC 136 ms
85,248 KB
testcase_29 WA -
testcase_30 AC 141 ms
94,260 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
g = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

leaf = [v for v in range(n) if len(g[v]) == 1]
three = [v for v in range(n) if len(g[v]) == 0]

if len(three) >= 2:
    print("No")
    exit()
if len(three) == 0:
    print("Yes")
    exit()

s = three[0]
dist = [-1]*n
dist[s] = 0
parent = [-1]*n
q = [s]
for v in q:
    for c in g[v]:
        if c == parent[v]:
            continue
        parent[c] = v
        dist[c] = dist[v] + 1
        q.append(c)

v = leaf[0]
print("Yes" if all(dist[v] == dist[vi] for vi in leaf) else "No")
0