結果

問題 No.1424 Ultrapalindrome
ユーザー あかりきあかりき
提出日時 2021-03-12 22:59:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 1,041 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 107,776 KB
最終ジャッジ日時 2024-04-22 17:15:14
合計ジャッジ時間 4,960 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
51,968 KB
testcase_01 AC 42 ms
51,968 KB
testcase_02 AC 39 ms
52,096 KB
testcase_03 AC 38 ms
52,096 KB
testcase_04 AC 40 ms
52,352 KB
testcase_05 AC 43 ms
52,096 KB
testcase_06 AC 39 ms
52,224 KB
testcase_07 AC 37 ms
52,480 KB
testcase_08 AC 38 ms
52,224 KB
testcase_09 AC 163 ms
89,472 KB
testcase_10 AC 165 ms
89,472 KB
testcase_11 AC 146 ms
88,960 KB
testcase_12 AC 162 ms
92,800 KB
testcase_13 AC 110 ms
80,384 KB
testcase_14 AC 145 ms
86,144 KB
testcase_15 AC 41 ms
53,376 KB
testcase_16 AC 137 ms
82,048 KB
testcase_17 AC 147 ms
87,296 KB
testcase_18 AC 144 ms
85,888 KB
testcase_19 AC 171 ms
90,112 KB
testcase_20 AC 109 ms
79,872 KB
testcase_21 AC 150 ms
87,296 KB
testcase_22 AC 131 ms
83,584 KB
testcase_23 AC 91 ms
77,312 KB
testcase_24 AC 112 ms
78,208 KB
testcase_25 AC 106 ms
77,824 KB
testcase_26 AC 195 ms
92,800 KB
testcase_27 AC 188 ms
92,800 KB
testcase_28 AC 156 ms
87,552 KB
testcase_29 AC 185 ms
99,584 KB
testcase_30 AC 193 ms
107,776 KB
testcase_31 AC 178 ms
107,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)

ct=0
L=[]
for i in range(n):
  if len(connection[i])>=3:
    ct+=1
    x=i
  if len(connection[i])==1:
    L.append(i)

if ct==0:
  print('Yes')
  exit()

if ct>=2:
  print('No')
  exit()

def bfs(v):
  distance=[-1]*n
  distance[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while len(next)!=0 and visitct!=n:
    ct+=1
    for i in range(len(next)):
      if visited[next[i]]==-1:
        distance[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return distance

B=bfs(x)
ans=[]
for i in range(len(L)):
  y=L[i]
  ans.append(B[y])
if len(set(ans))!=1:
  print('No')
  exit()
print('Yes')
0