結果

問題 No.1147 土偶Ⅱ
ユーザー first_vilfirst_vil
提出日時 2020-08-06 11:06:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 101 ms / 500 ms
コード長 981 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 82,468 KB
実行使用メモリ 77,412 KB
最終ジャッジ日時 2024-04-19 18:05:15
合計ジャッジ時間 2,556 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
54,144 KB
testcase_01 AC 37 ms
53,760 KB
testcase_02 AC 35 ms
53,888 KB
testcase_03 AC 35 ms
53,888 KB
testcase_04 AC 65 ms
72,704 KB
testcase_05 AC 44 ms
62,336 KB
testcase_06 AC 88 ms
77,184 KB
testcase_07 AC 83 ms
76,768 KB
testcase_08 AC 56 ms
66,816 KB
testcase_09 AC 86 ms
77,184 KB
testcase_10 AC 65 ms
72,832 KB
testcase_11 AC 95 ms
76,708 KB
testcase_12 AC 77 ms
76,800 KB
testcase_13 AC 60 ms
70,108 KB
testcase_14 AC 101 ms
76,784 KB
testcase_15 AC 72 ms
74,368 KB
testcase_16 AC 63 ms
69,504 KB
testcase_17 AC 43 ms
59,520 KB
testcase_18 AC 55 ms
65,152 KB
testcase_19 AC 90 ms
77,412 KB
testcase_20 AC 41 ms
59,392 KB
testcase_21 AC 37 ms
53,888 KB
testcase_22 AC 85 ms
76,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
  from collections import deque
  n,m=map(int,input().split())
  g=[[] for _ in range(n)]
  for _ in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)
  dp=[[[False]*n for j in range(n)] for i in range(3)]
  for i in range(n):
    dp[0][i][i]=True
  bfs=deque([i*1000+i for i in range(n)])
  pop=bfs.popleft
  push=bfs.append
  while bfs:
    v=pop()
    d=v//1000000
    v%=1000000
    s=v//1000
    cur=v%1000
    if d==2:
      continue
    for to in g[cur]:
      if dp[d+1][s][to]:
        continue
      dp[d+1][s][to]=True
      push((d+1)*1000000+s*1000+to)
  ans=n*(n-1)*(n-2)//6
  for i in range(n):
    for j in range(i+1,n):
      for k in range(j+1,n):
        if not(dp[0][i][j] or dp[1][i][j]) and dp[2][i][j]:
          ans-=1
        elif not(dp[0][j][k] or dp[1][j][k]) and dp[2][j][k]:
          ans-=1
        elif not(dp[0][k][i] or dp[1][k][i]) and dp[2][k][i]:
          ans-=1
  print(ans)
main()
0