結果

問題 No.1424 Ultrapalindrome
ユーザー convexineqconvexineq
提出日時 2021-03-13 02:53:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 484 ms
コンパイル使用メモリ 82,480 KB
実行使用メモリ 106,236 KB
最終ジャッジ日時 2024-04-22 17:20:13
合計ジャッジ時間 5,453 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,224 KB
testcase_01 AC 38 ms
52,352 KB
testcase_02 AC 37 ms
52,096 KB
testcase_03 AC 36 ms
52,608 KB
testcase_04 AC 37 ms
52,096 KB
testcase_05 AC 37 ms
52,096 KB
testcase_06 AC 38 ms
52,224 KB
testcase_07 AC 38 ms
51,968 KB
testcase_08 AC 38 ms
52,096 KB
testcase_09 AC 164 ms
87,040 KB
testcase_10 AC 149 ms
87,052 KB
testcase_11 AC 132 ms
82,432 KB
testcase_12 AC 147 ms
86,472 KB
testcase_13 AC 91 ms
77,616 KB
testcase_14 AC 135 ms
82,752 KB
testcase_15 AC 39 ms
53,248 KB
testcase_16 AC 122 ms
82,044 KB
testcase_17 AC 126 ms
82,720 KB
testcase_18 AC 130 ms
83,992 KB
testcase_19 AC 154 ms
86,736 KB
testcase_20 AC 95 ms
77,952 KB
testcase_21 AC 134 ms
84,400 KB
testcase_22 AC 110 ms
80,128 KB
testcase_23 AC 79 ms
77,556 KB
testcase_24 AC 91 ms
78,080 KB
testcase_25 AC 88 ms
78,152 KB
testcase_26 AC 177 ms
91,264 KB
testcase_27 AC 188 ms
90,732 KB
testcase_28 AC 130 ms
85,708 KB
testcase_29 AC 145 ms
95,496 KB
testcase_30 AC 160 ms
97,844 KB
testcase_31 AC 162 ms
106,236 KB
権限があれば一括ダウンロードができます

ソースコード

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]) >= 3]

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