結果

問題 No.1424 Ultrapalindrome
ユーザー tobusakanatobusakana
提出日時 2022-10-14 21:36:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,193 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 105,516 KB
最終ジャッジ日時 2023-09-08 20:27:23
合計ジャッジ時間 6,213 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,080 KB
testcase_01 AC 71 ms
71,176 KB
testcase_02 AC 76 ms
71,400 KB
testcase_03 AC 70 ms
71,304 KB
testcase_04 AC 71 ms
71,084 KB
testcase_05 AC 71 ms
71,288 KB
testcase_06 AC 75 ms
71,380 KB
testcase_07 WA -
testcase_08 AC 72 ms
71,348 KB
testcase_09 AC 186 ms
86,392 KB
testcase_10 AC 187 ms
86,136 KB
testcase_11 AC 158 ms
82,748 KB
testcase_12 AC 182 ms
85,920 KB
testcase_13 AC 122 ms
78,804 KB
testcase_14 AC 162 ms
83,332 KB
testcase_15 AC 76 ms
71,308 KB
testcase_16 AC 151 ms
82,484 KB
testcase_17 AC 160 ms
83,004 KB
testcase_18 AC 165 ms
82,480 KB
testcase_19 AC 212 ms
85,452 KB
testcase_20 AC 142 ms
78,892 KB
testcase_21 AC 178 ms
83,912 KB
testcase_22 AC 149 ms
81,648 KB
testcase_23 AC 112 ms
78,284 KB
testcase_24 AC 128 ms
78,640 KB
testcase_25 AC 128 ms
78,444 KB
testcase_26 AC 220 ms
86,800 KB
testcase_27 AC 220 ms
91,028 KB
testcase_28 AC 184 ms
90,752 KB
testcase_29 WA -
testcase_30 AC 204 ms
105,516 KB
testcase_31 AC 197 ms
98,604 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
    
more_indeg = 0
for v in range(N):
    if indegree[v] > 2:
        more_indeg += 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 more_indeg < 2 and check(start) and check(start1):
    print("Yes")
else:
    print("No")
0