結果

問題 No.1424 Ultrapalindrome
ユーザー titiatitia
提出日時 2021-03-12 21:53:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 431 ms / 2,000 ms
コード長 1,121 bytes
コンパイル時間 579 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 36,224 KB
最終ジャッジ日時 2024-04-22 17:04:57
合計ジャッジ時間 7,112 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 31 ms
10,880 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 29 ms
10,752 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 29 ms
10,880 KB
testcase_07 AC 30 ms
10,880 KB
testcase_08 AC 30 ms
10,752 KB
testcase_09 AC 277 ms
24,320 KB
testcase_10 AC 267 ms
24,448 KB
testcase_11 AC 194 ms
20,608 KB
testcase_12 AC 244 ms
23,680 KB
testcase_13 AC 85 ms
14,464 KB
testcase_14 AC 209 ms
21,504 KB
testcase_15 AC 30 ms
10,880 KB
testcase_16 AC 161 ms
19,072 KB
testcase_17 AC 193 ms
20,736 KB
testcase_18 AC 210 ms
18,048 KB
testcase_19 AC 328 ms
21,760 KB
testcase_20 AC 93 ms
13,568 KB
testcase_21 AC 268 ms
22,656 KB
testcase_22 AC 167 ms
16,640 KB
testcase_23 AC 55 ms
12,288 KB
testcase_24 AC 86 ms
14,080 KB
testcase_25 AC 83 ms
13,824 KB
testcase_26 AC 371 ms
24,064 KB
testcase_27 AC 322 ms
28,672 KB
testcase_28 AC 431 ms
35,968 KB
testcase_29 AC 416 ms
36,224 KB
testcase_30 AC 395 ms
28,196 KB
testcase_31 AC 323 ms
30,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
E=[[] for i in range(N)]
ED=[0]*N
for i in range(N-1):
    x,y=map(int,input().split())
    E[x-1].append(y-1)
    E[y-1].append(x-1)
    ED[x-1]+=1
    ED[y-1]+=1

root=-1
for i in range(N):
    if ED[i]==1:
        if root==-1:            
            Q=[i]
            root=i

count=0
for i in range(N):
    if ED[i]>2:
        count+=1

if count>=2:
    print("No")
    exit()

L=[0]*N
while Q:
    x=Q.pop()
    for to in E[x]:
        if L[to]==0:
            L[to]=L[x]+1
            Q.append(to)

L[root]=0

flag=1
MAX=max(L)

for i in range(N):
    if ED[i]==1:
        if L[i]==MAX or i==root:
            True
        else:
            print("No")
            exit()

root=L.index(MAX)
Q=[root]

L2=[0]*N
while Q:
    x=Q.pop()
    for to in E[x]:
        if L2[to]==0:
            L2[to]=L2[x]+1
            Q.append(to)

L2[root]=0

flag=1
MAX2=max(L2)

if MAX!=MAX2:
    print("No")
    exit()

for i in range(N):
    if ED[i]==1:
        if L2[i]==MAX or i==root:
            True
        else:
            print("No")
            exit()

print("Yes")
0