結果

問題 No.1424 Ultrapalindrome
ユーザー roarisroaris
提出日時 2021-03-12 21:49:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 100,084 KB
最終ジャッジ日時 2024-04-22 17:02:37
合計ジャッジ時間 4,859 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,016 KB
testcase_01 AC 41 ms
53,632 KB
testcase_02 AC 46 ms
54,016 KB
testcase_03 AC 44 ms
53,632 KB
testcase_04 AC 42 ms
53,504 KB
testcase_05 AC 42 ms
53,760 KB
testcase_06 AC 43 ms
54,144 KB
testcase_07 AC 42 ms
53,888 KB
testcase_08 AC 42 ms
53,504 KB
testcase_09 AC 122 ms
85,504 KB
testcase_10 AC 129 ms
85,248 KB
testcase_11 AC 101 ms
80,896 KB
testcase_12 AC 121 ms
84,864 KB
testcase_13 AC 91 ms
78,720 KB
testcase_14 AC 113 ms
83,712 KB
testcase_15 AC 44 ms
54,016 KB
testcase_16 AC 97 ms
80,384 KB
testcase_17 AC 106 ms
80,768 KB
testcase_18 AC 112 ms
80,384 KB
testcase_19 AC 137 ms
84,224 KB
testcase_20 AC 88 ms
78,592 KB
testcase_21 AC 117 ms
81,024 KB
testcase_22 AC 101 ms
80,000 KB
testcase_23 AC 68 ms
71,296 KB
testcase_24 AC 88 ms
78,080 KB
testcase_25 AC 86 ms
77,952 KB
testcase_26 AC 139 ms
85,376 KB
testcase_27 AC 142 ms
87,936 KB
testcase_28 AC 102 ms
85,504 KB
testcase_29 AC 119 ms
88,960 KB
testcase_30 AC 140 ms
99,976 KB
testcase_31 AC 141 ms
100,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

def bfs():
    dist = [-1]*N
    dist[l[0]] = 0
    q = deque([l[0]])
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if dist[nv]==-1:
                dist[nv] = dist[v]+1
                q.append(nv)
    
    return dist

N = int(input())
deg = [0]*N
G = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(int, input().split())
    deg[a-1] += 1
    deg[b-1] += 1
    G[a-1].append(b-1)
    G[b-1].append(a-1)

if max(deg)<=2:
    print('Yes')
    exit()

l = []

for i in range(N):
    if deg[i]>=3:
        l.append(i)
    
if len(l)>=2:
    print('No')
    exit()

dist = bfs()
dl = []

for i in range(N):
    if deg[i]==1:
        dl.append(dist[i])

if dl==[dl[0]]*len(dl):
    print('Yes')
else:
    print('No')
0