結果

問題 No.1424 Ultrapalindrome
ユーザー brthyyjpbrthyyjp
提出日時 2021-03-12 23:33:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 777 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 103,460 KB
最終ジャッジ日時 2024-04-22 17:16:42
合計ジャッジ時間 4,319 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,928 KB
testcase_01 AC 41 ms
54,016 KB
testcase_02 AC 38 ms
52,480 KB
testcase_03 AC 37 ms
52,224 KB
testcase_04 AC 37 ms
52,224 KB
testcase_05 AC 36 ms
52,096 KB
testcase_06 AC 41 ms
53,760 KB
testcase_07 AC 41 ms
53,504 KB
testcase_08 AC 37 ms
52,224 KB
testcase_09 AC 114 ms
85,616 KB
testcase_10 AC 123 ms
85,256 KB
testcase_11 AC 98 ms
83,128 KB
testcase_12 AC 122 ms
84,980 KB
testcase_13 AC 65 ms
72,604 KB
testcase_14 AC 111 ms
83,316 KB
testcase_15 AC 38 ms
52,608 KB
testcase_16 AC 97 ms
82,056 KB
testcase_17 AC 110 ms
83,136 KB
testcase_18 AC 113 ms
81,760 KB
testcase_19 AC 145 ms
83,484 KB
testcase_20 AC 80 ms
75,264 KB
testcase_21 AC 125 ms
82,264 KB
testcase_22 AC 103 ms
80,640 KB
testcase_23 AC 70 ms
68,864 KB
testcase_24 AC 82 ms
72,832 KB
testcase_25 AC 80 ms
72,192 KB
testcase_26 AC 159 ms
85,172 KB
testcase_27 AC 126 ms
88,692 KB
testcase_28 AC 91 ms
84,736 KB
testcase_29 AC 107 ms
89,396 KB
testcase_30 AC 127 ms
102,204 KB
testcase_31 AC 124 ms
103,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

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

G = []
L = []
for i in range(n):
    if len(g[i]) >= 3:
        G.append(i)
    if len(g[i]) == 1:
        L.append(i)

if len(G) >= 2:
    print('No')
    exit()

if not G:
    print('Yes')
    exit()

s = G[0]
from collections import deque
q = deque([])
q.append(s)
dist = [-1]*n
dist[s] = 0
while q:
    v = q.popleft()
    for u in g[v]:
        if dist[u] == -1:
            dist[u] = dist[v]+1
            q.append(u)
D = set()
for l in L:
    D.add(dist[l])
#print(D)
if len(D) == 1:
    print('Yes')
else:
    print('No')
0