結果

問題 No.1424 Ultrapalindrome
ユーザー tobusakanatobusakana
提出日時 2022-10-14 21:34:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,087 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 86,648 KB
実行使用メモリ 106,384 KB
最終ジャッジ日時 2023-09-08 20:24:28
合計ジャッジ時間 6,624 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,216 KB
testcase_01 AC 66 ms
70,988 KB
testcase_02 AC 66 ms
71,208 KB
testcase_03 AC 68 ms
71,096 KB
testcase_04 AC 69 ms
71,040 KB
testcase_05 AC 70 ms
70,888 KB
testcase_06 AC 70 ms
70,988 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 218 ms
87,368 KB
testcase_10 AC 220 ms
87,652 KB
testcase_11 AC 173 ms
84,596 KB
testcase_12 AC 202 ms
86,504 KB
testcase_13 AC 126 ms
78,840 KB
testcase_14 AC 178 ms
85,064 KB
testcase_15 AC 71 ms
71,096 KB
testcase_16 AC 158 ms
82,920 KB
testcase_17 AC 180 ms
84,700 KB
testcase_18 AC 159 ms
82,148 KB
testcase_19 AC 185 ms
85,076 KB
testcase_20 AC 124 ms
78,444 KB
testcase_21 AC 175 ms
83,760 KB
testcase_22 AC 145 ms
81,428 KB
testcase_23 AC 106 ms
77,880 KB
testcase_24 AC 124 ms
78,340 KB
testcase_25 AC 123 ms
78,236 KB
testcase_26 AC 219 ms
86,100 KB
testcase_27 WA -
testcase_28 AC 176 ms
90,680 KB
testcase_29 WA -
testcase_30 AC 200 ms
106,384 KB
testcase_31 AC 195 ms
98,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
G = [[] for i in range(N)]
indegree = [0] * N
for _ in range(N - 1):
    a,b = map(int,input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)
    indegree[a - 1] += 1
    indegree[b - 1] += 1
    
# 次数1のある点から、他の全ての点への距離が同じであればOK
# を二回やって成功すればOK
start = -1
start1 = -1
for v in range(N):
    if indegree[v] == 1 and start != -1:
        start1 = v
        break
    if indegree[v] == 1:
        start = v

def check(x):
    stack = []
    dist = [-1] * N
    stack.append([start, 0])
    while stack:
        v, d = stack.pop()
        if dist[v] != -1:
            continue
        dist[v] = d
        for child in G[v]:
            if dist[child] != -1:
                continue
            stack.append([child, d + 1])
        
    ds = set()
    for v in range(N):
        if v == start:
            continue
        if indegree[v] == 1:
            ds.add(dist[v])
            
    return len(ds) == 1

if check(start) and check(start1):
    print("Yes")
else:
    print("No")
0