結果

問題 No.1424 Ultrapalindrome
ユーザー 小野寺健小野寺健
提出日時 2021-05-20 14:00:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 597 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 817,920 KB
最終ジャッジ日時 2024-04-18 14:02:43
合計ジャッジ時間 3,244 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 AC 29 ms
10,752 KB
testcase_03 AC 28 ms
10,624 KB
testcase_04 AC 31 ms
10,752 KB
testcase_05 AC 29 ms
10,752 KB
testcase_06 AC 28 ms
10,752 KB
testcase_07 AC 29 ms
10,752 KB
testcase_08 AC 30 ms
10,624 KB
testcase_09 MLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import combinations

N = int(input())

P = [0] * N

D = [[float('inf')] * N for _ in range(N)]

for i in range(N):
    D[i][i] = 0

for _ in range(N-1):
    v, u = map(int, input().split())
    D[v-1][u-1] = D[u-1][v-1] = 1
    P[v-1] += 1
    P[u-1] += 1
    
for k in range(N):
    for i in range(N):
        for j in range(N):
            D[i][j] = min(D[i][j], D[i][k] + D[k][j])

val = 0
for i, j in combinations([k for k, v in enumerate(P) if v == 1], 2):
    if val == 0:
        val = D[i][j]
    elif val != D[i][j]:
        print('No')
        break
else:
    print('Yes')
0