結果

問題 No.1424 Ultrapalindrome
ユーザー rlangevinrlangevin
提出日時 2023-03-01 22:53:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,078 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 103,368 KB
最終ジャッジ日時 2023-10-15 02:28:05
合計ジャッジ時間 9,114 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
71,604 KB
testcase_01 AC 99 ms
71,692 KB
testcase_02 AC 99 ms
71,620 KB
testcase_03 AC 98 ms
71,856 KB
testcase_04 AC 95 ms
71,560 KB
testcase_05 AC 98 ms
71,644 KB
testcase_06 AC 96 ms
71,828 KB
testcase_07 AC 99 ms
71,664 KB
testcase_08 WA -
testcase_09 AC 225 ms
90,384 KB
testcase_10 AC 245 ms
90,676 KB
testcase_11 AC 195 ms
85,100 KB
testcase_12 AC 223 ms
89,852 KB
testcase_13 AC 148 ms
81,056 KB
testcase_14 AC 201 ms
87,696 KB
testcase_15 AC 100 ms
71,656 KB
testcase_16 AC 182 ms
84,584 KB
testcase_17 AC 195 ms
85,560 KB
testcase_18 AC 182 ms
83,484 KB
testcase_19 AC 228 ms
86,324 KB
testcase_20 AC 135 ms
77,992 KB
testcase_21 AC 191 ms
84,768 KB
testcase_22 AC 169 ms
82,352 KB
testcase_23 AC 125 ms
78,116 KB
testcase_24 AC 137 ms
78,068 KB
testcase_25 AC 137 ms
78,312 KB
testcase_26 AC 249 ms
88,548 KB
testcase_27 WA -
testcase_28 AC 166 ms
91,612 KB
testcase_29 AC 169 ms
91,672 KB
testcase_30 AC 192 ms
103,368 KB
testcase_31 AC 176 ms
98,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
from collections import deque


def bfs(G, s, N):
    Q = deque([])
    dist = [-1] * N
    par = [-1] * N
    dist[s] = 0
    for u in G[s]:
        par[u] = s
        dist[u] = 1
        Q.append(u)

    while Q:
        u = Q.popleft()
        for v in G[u]:
            if dist[v] != -1:
                continue
            dist[v] = dist[u] + 1
            par[v] = u
            Q.append(v)
            
    return dist


N = int(readline())
G = [[] for i in range(N)]
D = [0] * N
for i in range(N - 1):
    A, B = map(int, readline().split())
    A, B = A - 1, B - 1
    G[A].append(B)
    G[B].append(A)
    D[A] += 1
    D[B] += 1
    
one = []
for i in range(N):
    if D[i] == 1:
        one.append(i)
        
D1 = bfs(G, one[0], N)
S1 = set()
for a in one:
    if D1[a] == 0:
        continue
    S1.add(D1[a])
if len(S1) != 1:
    print("No")
    exit()
    
D1 = bfs(G, one[1], N)
S1 = set()
for a in one:
    if D1[a] == 0:
        continue
    S1.add(D1[a])
if len(S1) != 1:
    print("No")
    exit()
    
print("Yes")
0