結果

問題 No.1424 Ultrapalindrome
ユーザー rodearodea
提出日時 2021-03-18 15:43:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 857 ms / 2,000 ms
コード長 747 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 37,632 KB
最終ジャッジ日時 2024-04-28 05:57:27
合計ジャッジ時間 10,601 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
11,136 KB
testcase_01 AC 35 ms
10,880 KB
testcase_02 AC 35 ms
10,880 KB
testcase_03 AC 35 ms
10,880 KB
testcase_04 AC 34 ms
10,880 KB
testcase_05 AC 34 ms
10,880 KB
testcase_06 AC 35 ms
10,880 KB
testcase_07 AC 35 ms
10,880 KB
testcase_08 AC 35 ms
11,008 KB
testcase_09 AC 403 ms
23,936 KB
testcase_10 AC 408 ms
23,936 KB
testcase_11 AC 291 ms
20,224 KB
testcase_12 AC 374 ms
23,168 KB
testcase_13 AC 123 ms
14,336 KB
testcase_14 AC 307 ms
20,992 KB
testcase_15 AC 35 ms
11,008 KB
testcase_16 AC 250 ms
18,944 KB
testcase_17 AC 300 ms
20,608 KB
testcase_18 AC 384 ms
18,688 KB
testcase_19 AC 577 ms
21,504 KB
testcase_20 AC 161 ms
13,312 KB
testcase_21 AC 455 ms
19,072 KB
testcase_22 AC 302 ms
16,256 KB
testcase_23 AC 91 ms
12,672 KB
testcase_24 AC 146 ms
13,184 KB
testcase_25 AC 137 ms
12,928 KB
testcase_26 AC 673 ms
23,168 KB
testcase_27 AC 504 ms
27,904 KB
testcase_28 AC 438 ms
27,520 KB
testcase_29 AC 813 ms
28,288 KB
testcase_30 AC 834 ms
34,560 KB
testcase_31 AC 857 ms
37,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import queue

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

deg3 = 0
cv = -1
for i in range(n):
    if 3 <= len(G[i]):
        deg3 += 1
        cv = i

if deg3 >= 2:
    print("No")
    exit()

if deg3 == 0:
    print("Yes")
    exit()

que = queue.Queue()
que.put([cv, 0])
visited = [False for i in range(n)]
visited[cv] = True
leaf = set()
while not que.empty():
    cv, d = que.get()
    is_leaf = True
    for nv in G[cv]:
        if visited[nv]: continue
        visited[nv] = True
        is_leaf = False
        que.put([nv, d + 1])

    if is_leaf: leaf.add(d)

if len(leaf) == 1:
    print("Yes")
else:
    print("No")
0