結果

問題 No.1424 Ultrapalindrome
ユーザー titiatitia
提出日時 2021-03-12 21:40:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,035 bytes
コンパイル時間 426 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 35,968 KB
最終ジャッジ日時 2024-04-22 12:30:29
合計ジャッジ時間 9,089 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,880 KB
testcase_01 AC 31 ms
10,880 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 WA -
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 31 ms
10,880 KB
testcase_06 AC 31 ms
10,880 KB
testcase_07 AC 30 ms
10,880 KB
testcase_08 WA -
testcase_09 AC 468 ms
25,728 KB
testcase_10 AC 460 ms
25,600 KB
testcase_11 AC 325 ms
21,248 KB
testcase_12 AC 432 ms
24,832 KB
testcase_13 AC 127 ms
14,720 KB
testcase_14 AC 359 ms
22,272 KB
testcase_15 AC 31 ms
11,008 KB
testcase_16 AC 283 ms
19,968 KB
testcase_17 AC 335 ms
21,632 KB
testcase_18 AC 230 ms
18,176 KB
testcase_19 AC 347 ms
21,760 KB
testcase_20 AC 96 ms
13,568 KB
testcase_21 AC 295 ms
22,656 KB
testcase_22 AC 178 ms
16,384 KB
testcase_23 AC 61 ms
12,160 KB
testcase_24 AC 94 ms
13,952 KB
testcase_25 AC 88 ms
13,696 KB
testcase_26 AC 423 ms
23,936 KB
testcase_27 WA -
testcase_28 AC 410 ms
35,840 KB
testcase_29 AC 415 ms
35,968 KB
testcase_30 AC 408 ms
28,024 KB
testcase_31 AC 400 ms
31,164 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
        else:
            root2=i
            Q2=[i]

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)

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

flag=1
MAX=max(L)
MAX2=max(L2)

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

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

print("Yes")
0