結果

問題 No.1147 土偶Ⅱ
ユーザー brthyyjpbrthyyjp
提出日時 2021-01-26 15:37:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 133 ms / 500 ms
コード長 633 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 78,256 KB
最終ジャッジ日時 2023-09-05 19:40:36
合計ジャッジ時間 4,342 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
75,312 KB
testcase_01 AC 76 ms
71,376 KB
testcase_02 AC 76 ms
71,500 KB
testcase_03 AC 75 ms
71,256 KB
testcase_04 AC 104 ms
76,432 KB
testcase_05 AC 84 ms
76,312 KB
testcase_06 AC 133 ms
77,676 KB
testcase_07 AC 107 ms
76,076 KB
testcase_08 AC 89 ms
76,452 KB
testcase_09 AC 117 ms
78,256 KB
testcase_10 AC 95 ms
76,080 KB
testcase_11 AC 108 ms
76,376 KB
testcase_12 AC 101 ms
76,360 KB
testcase_13 AC 91 ms
76,512 KB
testcase_14 AC 102 ms
76,312 KB
testcase_15 AC 105 ms
76,440 KB
testcase_16 AC 92 ms
76,432 KB
testcase_17 AC 78 ms
75,472 KB
testcase_18 AC 87 ms
76,328 KB
testcase_19 AC 114 ms
77,768 KB
testcase_20 AC 81 ms
76,036 KB
testcase_21 AC 74 ms
71,048 KB
testcase_22 AC 118 ms
77,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
INF =10**18
d = [[INF]*n for i in range(n)]
for i in range(n):
    d[i][i] = 0
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    d[a][b] = 1
    d[b][a] = 1

def warshal_floyd(d):
    n = len(d)
    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])
    return d

d = warshal_floyd(d)
ans = n*(n-1)*(n-2)//6
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if d[i][j] == 2 or d[j][k] == 2 or d[k][i] == 2:
                ans -= 1
print(ans)
0