結果

問題 No.1424 Ultrapalindrome
ユーザー convexineqconvexineq
提出日時 2021-03-12 21:58:24
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 740 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 129,596 KB
最終ジャッジ日時 2023-08-04 19:01:55
合計ジャッジ時間 6,698 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,460 KB
testcase_01 AC 68 ms
71,472 KB
testcase_02 AC 68 ms
71,348 KB
testcase_03 AC 67 ms
71,260 KB
testcase_04 AC 66 ms
71,236 KB
testcase_05 AC 68 ms
71,272 KB
testcase_06 AC 68 ms
71,436 KB
testcase_07 AC 68 ms
71,472 KB
testcase_08 AC 68 ms
71,236 KB
testcase_09 AC 194 ms
93,576 KB
testcase_10 AC 185 ms
93,676 KB
testcase_11 AC 156 ms
88,312 KB
testcase_12 AC 176 ms
92,472 KB
testcase_13 AC 122 ms
79,836 KB
testcase_14 AC 172 ms
89,180 KB
testcase_15 AC 69 ms
71,188 KB
testcase_16 AC 155 ms
86,348 KB
testcase_17 AC 165 ms
87,952 KB
testcase_18 AC 204 ms
96,928 KB
testcase_19 AC 291 ms
106,184 KB
testcase_20 AC 133 ms
79,492 KB
testcase_21 AC 220 ms
103,020 KB
testcase_22 AC 176 ms
93,864 KB
testcase_23 AC 104 ms
78,168 KB
testcase_24 AC 128 ms
79,236 KB
testcase_25 AC 130 ms
79,240 KB
testcase_26 AC 337 ms
111,412 KB
testcase_27 WA -
testcase_28 AC 174 ms
104,096 KB
testcase_29 AC 173 ms
104,260 KB
testcase_30 AC 255 ms
129,596 KB
testcase_31 AC 178 ms
104,392 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]

def dfs(g,s):
    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)
    d = -1
    for v in leaf:
        if s == v: continue
        elif d == -1:
            d = dist[v]
        elif d != dist[v]:
            print("No")
            exit()
    #print(dist,d)

#print(leaf)

c = 0
for s in leaf:
    dfs(g,s)
    c += 1
    if c > 10: break
print("Yes")
0