結果

問題 No.1424 Ultrapalindrome
ユーザー rodearodea
提出日時 2021-03-18 15:43:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 693 ms / 2,000 ms
コード長 747 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 35,452 KB
最終ジャッジ日時 2023-08-10 12:41:59
合計ジャッジ時間 9,376 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
9,104 KB
testcase_01 AC 23 ms
8,984 KB
testcase_02 AC 22 ms
9,108 KB
testcase_03 AC 22 ms
9,044 KB
testcase_04 AC 23 ms
8,960 KB
testcase_05 AC 23 ms
9,140 KB
testcase_06 AC 23 ms
8,928 KB
testcase_07 AC 21 ms
9,048 KB
testcase_08 AC 22 ms
9,108 KB
testcase_09 AC 331 ms
22,080 KB
testcase_10 AC 329 ms
21,756 KB
testcase_11 AC 235 ms
18,152 KB
testcase_12 AC 308 ms
21,208 KB
testcase_13 AC 97 ms
12,284 KB
testcase_14 AC 250 ms
19,004 KB
testcase_15 AC 24 ms
9,000 KB
testcase_16 AC 204 ms
16,756 KB
testcase_17 AC 240 ms
18,524 KB
testcase_18 AC 308 ms
16,912 KB
testcase_19 AC 473 ms
19,428 KB
testcase_20 AC 125 ms
11,628 KB
testcase_21 AC 365 ms
17,096 KB
testcase_22 AC 236 ms
14,444 KB
testcase_23 AC 68 ms
10,772 KB
testcase_24 AC 114 ms
11,236 KB
testcase_25 AC 108 ms
11,052 KB
testcase_26 AC 571 ms
21,148 KB
testcase_27 AC 415 ms
25,852 KB
testcase_28 AC 347 ms
25,484 KB
testcase_29 AC 653 ms
26,144 KB
testcase_30 AC 653 ms
32,308 KB
testcase_31 AC 693 ms
35,452 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