結果

問題 No.1424 Ultrapalindrome
ユーザー AEnAEn
提出日時 2022-11-30 23:27:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 212 ms / 2,000 ms
コード長 915 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 82,280 KB
実行使用メモリ 104,248 KB
最終ジャッジ日時 2024-04-16 18:47:22
合計ジャッジ時間 5,186 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,016 KB
testcase_01 AC 43 ms
53,760 KB
testcase_02 AC 46 ms
54,016 KB
testcase_03 AC 41 ms
53,888 KB
testcase_04 AC 42 ms
53,888 KB
testcase_05 AC 41 ms
54,144 KB
testcase_06 AC 41 ms
54,016 KB
testcase_07 AC 42 ms
54,144 KB
testcase_08 AC 42 ms
54,016 KB
testcase_09 AC 184 ms
88,984 KB
testcase_10 AC 173 ms
88,960 KB
testcase_11 AC 143 ms
83,856 KB
testcase_12 AC 177 ms
88,448 KB
testcase_13 AC 100 ms
78,208 KB
testcase_14 AC 156 ms
85,912 KB
testcase_15 AC 45 ms
54,784 KB
testcase_16 AC 136 ms
82,960 KB
testcase_17 AC 145 ms
84,416 KB
testcase_18 AC 149 ms
83,060 KB
testcase_19 AC 184 ms
86,912 KB
testcase_20 AC 105 ms
78,084 KB
testcase_21 AC 157 ms
84,860 KB
testcase_22 AC 128 ms
82,032 KB
testcase_23 AC 86 ms
77,696 KB
testcase_24 AC 111 ms
78,080 KB
testcase_25 AC 99 ms
78,052 KB
testcase_26 AC 203 ms
90,304 KB
testcase_27 AC 212 ms
93,684 KB
testcase_28 AC 150 ms
93,708 KB
testcase_29 AC 158 ms
95,068 KB
testcase_30 AC 167 ms
102,936 KB
testcase_31 AC 170 ms
104,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N = int(input())
G = [list() for _ 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)

s1, s2 = [], []
for i in range(N):
    if len(G[i])==1:
        s1.append(i)
    else:
        s2.append(i)

if len(s1)==2:
    exit(print('Yes'))
else:
    cnt = 0
    s3 = []
    for s in s2:
        if len(G[s])>=3:
            cnt += 1
            s3.append(s)
    if cnt>1:
        exit(print('No'))
    else:
        d = deque([s3[0]])
        dis = [-1]*N
        dis[s3[0]] = 0
        while d:
            v = d.popleft()
            for nex in G[v]:
                if dis[nex]==-1:
                    dis[nex]= dis[v]+1
                    d.append(nex)
        dd = []
        for a in s1:
            dd.append(dis[a])
        if len(set(dd))==1:
            print('Yes')
        else:
            print('No')
0